I ended up using import * as GoogleSignIn from 'expo-google-sign-in'; instead of the import * as Google from 'expo-auth-session/providers/google';
It seems this is the only way I can get it to work properly.
Answer from Cornel Raiu on Stack OverflowI ended up using import * as GoogleSignIn from 'expo-google-sign-in'; instead of the import * as Google from 'expo-auth-session/providers/google';
It seems this is the only way I can get it to work properly.
Make sure you're not running your expo with an offline tag "expo start --offline" ---- this is wrong instead start it with "expo start"....... that was how i solved my issue on android
// code goes like these
import * as Google from 'expo-auth-session/providers/google';
const [request, response, promptAsync] = Google.useAuthRequest({
expoClientId: 'xxxxxxxx', //get this from google console
});
useEffect(() => {
if (response?.type === 'success') {
const { authentication } = response;
// an access token will be returned in the authentication object
getGoogleUser(authentication.accessToken)
}
}, [response]);
const getGoogleUser = async (accessToken) => {
try{
let gUserReq = await
axios.get('https://www.googleapis.com/oauth2/v2/userinfo',
{
headers: {
Authorization: `Bearer ${accessToken}`
}
}
);
console.log(gUserReq.data)
}
catch(error){
console.log('GoogleUserReq error: ', error);
}
}
Videos
I've been trying to set up google oauth for the android version of the application that I'm building. Below you will find a code snippet of the initial set up that I had. I have gone through several iterations of how I've been setting up the code to work with the android version however the error that I keep getting is a URI redirect mismatch. I understand what the error means but I'm not sure what I'm doing wrong.
In the google developers console in the android section, there are 3 inputs where I can enter information.
name: this doesn't matter AFAIK
Package.name: I've tried to set this either the scheme in my app.json or the android.package name
SHA-1 Fingerprint certificate: I got this value from doing eas credentials.
I'm fairly certain that I'm screwing up the package.name input.
App.json scheme: com.john-doe.mobile-client
android.package: com.john-doe.appname_android
Im going to make the scheme and the package name the same then will rebuild. I will probably need to update the sha-1 fingerprint certificate also after a rebuild. Once the build is done I'll come back to update this but I'm honestly stumped.
import { useAuthRequest } from "expo-auth-session/providers/google";
WebBrowser.maybeCompleteAuthSession();
const [request, response, promptAsync] = useAuthRequest({
androidClientId:
"myadroid-client-id.apps.googleusercontent.com",
iosClientId:
"myios-client-id.apps.googleusercontent.com",
});
// refactor this to not use useEfffect.
useEffect(() => {
if (response?.type === "success") {
const { authentication } = response;
const accessToken = authentication?.accessToken;
if (accessToken) {
saveAuthToken(accessToken)
.then(() => refreshSession())
.then(() => router.push("/"))
.catch((error) => {
console.error("Error saving token:", error);
});
}
}
}, [response]);What happened to seamless auth integrations with expo apps?
I'm using the expo-router and supabase. I want to implement google auth and I have two options:
expo-auth-session : the docs are not up to date, for implementing google auth with supabase the docs refer to the supabase docs which uses react-native-google-signin.
react-native-google-signin : the free/original version will be deprecated in 2025 so there's no point of using this and I do not want to use their paid version.
What should I do?
Hi there! I'm working in a personal project and I want to make a log in and sign up with google, then I have been working with expo-auth-session (https://docs.expo.dev/versions/latest/sdk/auth-session/) and google cloud. The issue is that when I make log in, it never gets back to my app, everytime it redirect to google.com
I'm working in android. How can I fix this problem? did you find this issue anytime?
thanks you for advice!
Edit: My login button component is this (it's just a test, I never do it before):
WebBrowser.maybeCompleteAuthSession();
export const Login = () => {
const [request, response, promptAsync] = Google.useAuthRequest({
androidClientId: config.GOOGLE_ANDROID_CLIENT_ID,
clientId: config.GOOGLE_ANDROID_CLIENT_ID,
});
const testSending = async (token: string) => {
console.log("=========================TOKEN========================");
console.log(token);
console.log("=================================================");
};
useEffect(() => {
if (response) {
if (response.type === 'success') {
const { authentication } = response;
testSending(authentication?.idToken || '');
console.log(authentication);
}else {
console.log("=========================FAILED========================");
console.log("Login failed");
console.log("=================================================");
}
}
}, [response])
return (
<Pressable onPress={() => promptAsync().catch((error) => console.error(error))} disabled={!request} style={{ padding: 10, backgroundColor: 'blue' }}>
<Text style={{ color: 'white' }}>Login with Google</Text>
</Pressable>
)
}Alternative 1 - Add responseType: 'id_token' in useAuthRequest
const [requestIdToken, responseIdToken, promptAsyncIdToken] =
Google.useAuthRequest({
responseType: 'id_token',
androidClientId: GOOGLE_CLIENT_ID_ANDROID,
iosClientId: GOOGLE_CLIENT_ID_IOS,
expoClientId: GOOGLE_CLIENT_WEB_EXPO,
scopes: ['profile', 'email'],
})
Alternative 2 - Try changing your useAuthRequest by useIdTokenAuthRequest
Replacing useAuthRequest for `useIdTokenAuthRequest worked perfectly for me.
In the docs they only show useIdTokenAuthRequest for use with firebase, but it works with all the same arguments as the normal useAuthRequest method
If someone is trying this now.
You can Follow This https://www.youtube.com/watch?v=hmZm_jPvWWM
In the code given in this video replace promptAsync({useProxy: false, showInRecents: true}) => promptAsync()
I ended up using expo-google-app-auth, for some reason that I'm yet to figure out, you have to use host.expo.exponent as your package name and bundle identifier in the google developer console for this library to work. Code:
import { Alert } from 'react-native';
import * as Google from 'expo-google-app-auth'
const GoogleLogin = async () => {
//Get those keys from the google developer console
const { iosClientId, androidClientId } = config.google
const { type, user } = await Google.logInAsync({
iosClientId,
androidClientId,
});
if (type === 'success') {
/* `accessToken` is now valid and can be used to get data from the Google API with HTTP requests */
return { email: user.email, id: user.id }
} else {
Alert.alert("Google login error.")
}
}
export default GoogleLogin;