4

I'm trying to implement google sign in in my expo using expo-auth-session, When I click on my gmail to sign in, I'm redirected to this screen saying "Something went wrong when trying to finish signing in. Please close this screen to go back to the app".

//Google auth code: import * as Google from 'expo-auth-session/providers/google'; const [request, response, promptAsync] = Google.useAuthRequest({ expoClientId: config.google.expoClientId, redirectUri: config.google.redirectUri, }); React.useEffect(() => { //Handle google login console.log(response) if (response?.type === 'success') { const { authentication } = response; } }, [response]); //Button that calls the google sign in <Button iconName={'google'} iconPressed={() => promptAsync({useProxy: true})} /> 
5
  • This is an open issue. Here the github page. Commented Dec 9, 2021 at 15:55
  • Thanks for your reply, I've seen the github but none of the comment there helped me, was hoping if someone here could provide some guidance. @GiovanniEsposito Commented Dec 9, 2021 at 16:13
  • So you already tried to set useProxy: false correct? Commented Dec 9, 2021 at 16:15
  • I did, yes. @GiovanniEsposito Commented Dec 10, 2021 at 9:19
  • same issue with me. here is my question stackoverflow.com/questions/73136119/… Commented Jul 27, 2022 at 10:24

3 Answers 3

1

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()

Sign up to request clarification or add additional context in comments.

Comments

0

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; 

1 Comment

what if I use my custom package & bundle name like com.bilal.profile instead of host.expo.exponent ?
0

I think you can try like this

import * as Google from 'expo-auth-session/providers/google'; import * as WebBrowser from 'expo-web-browser'; WebBrowser.maybeCompleteAuthSession(); .... const [request, response, promptAsync] = Google.useAuthRequest({ androidClientId: config.androidClientId, iosClientId: config.iosClientId, expoClientId: config.expoClientId, scopes: config.scopes, }); useEffect(() => { if (response?.type === 'success') { const { authentication } = response; getGoogleUser((authentication as any).accessToken) } }, [response]); const getGoogleUser = async (accessToken: string) => { try{ const response = await fetch('https://www.googleapis.com/userinfo/v2/me', { headers: { Authorization: `Bearer ${accessToken}`} }); const user = response.json() if (user?.email) { const { email, name } = user; // you will get more data in the user object ....... } } catch(error){ console.log('GoogleUserReq error: ', error); } } return ( <View> <Button onPress={() => promptAsync() } /> </View> ); 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.