Requirement: Get the id_token from Google Auth, which is used with firebase authentication.
I'm using Expo 47.
The authentication works fine on iOS. But it fails on Android devices.
Code used:
import * as Google from "expo-auth-session/providers/google";
import * as WebBrowser from "expo-web-browser";
WebBrowser.maybeCompleteAuthSession();
const isDev = process.env.NODE_ENV === 'development';
export default function GoogleAuth() {
const [request, response, promptAsync] = Google.useIdTokenAuthRequest({
androidClientId: "",
iosClientId: "",
clientId: "",
});
useEffect(() => {
if (!response) return;
if (response?.params?.id_token) {
// log in with firebase
} else {
console.log(response) // this logs: {"type":"dismiss"} in android APK
}
}, [response]);
if (!request) {
return null;
}
return (
<Button
onPress={() => promptAsync({ useProxy: isDev, showInRecents: true })}
title={"Continue with Google"}
/>
);
};
I tried using useAuthRequest
with responseType: 'id_token'
but it says the response type is invalid. How to fix this error?
Figured it out. The schema
of app.json
cannot have any uppercase letters. My packageName
and schema
was in the form of com.myapp.mobileApp
. The login worked fine when I changed them to com.myapp.mobileapp
.
Update: This won't work in Expo Go. You'll need to set up a Custom Dev Client to get this work: https://blog.expo.dev/introducing-custom-development-clients-5a2c79a9ddf8