react-native-google-sign-in icon indicating copy to clipboard operation
react-native-google-sign-in copied to clipboard

Always getting warning "possible unhandled promise rejection (id 0) 12501"

Open tareq0065 opened this issue 7 years ago • 6 comments

I am trying to work with it and after configure and run when I click on the sign in button is showing this warning and there is no output.

screenshot_1

Code i have used:

import React, { Component } from 'react'; import { Text, View, TouchableOpacity } from 'react-native'; import { StackNavigator, NavigationActions } from 'react-navigation'; import GoogleSignIn from 'react-native-google-sign-in';

export default class LoginScreen extends Component {
	constructor(props){
		super(props)
	}

	// async _signIn(){
	// 	GoogleSignin.configure({
			// scopes: [
			// 	'https://www.googleapis.com/auth/drive',
			// 	'https://www.googleapis.com/auth/drive.appdata',
			// 	'https://www.googleapis.com/auth/drive.file',
			// 	'https://www.googleapis.com/auth/drive.metadata',
			// 	'https://www.googleapis.com/auth/drive.metadata.readonly',
			// 	'https://www.googleapis.com/auth/drive.photos.readonly',
			// 	'openid',
			// 	'email',
			// 	'profile'
			// ],
			// iosClientId: '454510003783-ftcotf82ko3o37dt7gn91g2rmstsdhat.apps.googleusercontent.com', // only for iOS
			// webClientId: '454510003783-1iuf68qbrjsap6ubiekk6lfjlp62pgt1.apps.googleusercontent.com', // client ID of type WEB for your server (needed to verify user ID and offline access)
			// offlineAccess: true,
			// accountName: 'AllstarIQ' // [Android] specifies an account name on the device that should be used
	// 	})
	// 	.then(() => {
	// 		await GoogleSignin.currentUserAsync().then((user) => {
	// 			console.error('USER', user);
	// 			this.setState({user: user});
	// 		}).done();
	// 	});
	// }

	async _signIn() {
		await GoogleSignIn.configure({
			clientID: '531870286570-28gcrs4oin53rb0aoc8igkutfo2gfijr.apps.googleusercontent.com',
			scopes: [
                'https://www.googleapis.com/auth/drive',
                'https://www.googleapis.com/auth/drive.appdata',
                'https://www.googleapis.com/auth/drive.file',
                'https://www.googleapis.com/auth/drive.metadata',
                'https://www.googleapis.com/auth/drive.metadata.readonly',
                'https://www.googleapis.com/auth/drive.photos.readonly',
                'openid', 'email', 'profile'
            ],
			offlineAccess: true,
            forceCodeForRefreshToken: false
		});

		const user = await GoogleSignIn.signInPromise();
		setTimeout(() => {
			alert(JSON.stringify(user));
		}, 2000);
	}

    render() {
        return (
            <View style={{flex:1, justifyContent: 'center', alignItems: 'center'}}>
            <TouchableOpacity
                style={{width: 200, height: 68}}
				onPress={() => this._signIn()}>
				<Text>SignIn</Text>
				</TouchableOpacity>
            </View>
        )
    }
}

Is there any solution for this problem. Please help me out.

tareq0065 avatar Jul 07 '17 15:07 tareq0065

@tareq0065 This warning means you are not handling your promise errors. Are you sure you are providing error handler to all your promises?

Make sure to either use catch or provide two functions to then for all promises.

joonhocho avatar Jul 26 '17 22:07 joonhocho

@tareq0065 you can do something like:

...
try {
  await GoogleSignIn.configure({
    clientID: '531870286570-28gcrs4oin53rb0aoc8igkutfo2gfijr.apps.googleusercontent.com',
    scopes: [
      'https://www.googleapis.com/auth/drive',
      'https://www.googleapis.com/auth/drive.appdata',
      'https://www.googleapis.com/auth/drive.file',
      'https://www.googleapis.com/auth/drive.metadata',
      'https://www.googleapis.com/auth/drive.metadata.readonly',
      'https://www.googleapis.com/auth/drive.photos.readonly',
      'openid', 'email', 'profile'
    ],
    offlineAccess: true,
    forceCodeForRefreshToken: false
  });
  const user = await GoogleSignIn.signInPromise();
  setTimeout(() => {
    alert(JSON.stringify(user));
  }, 2000);
} catch (error) {
// At least this, but a better handler of the error is better
console.log(error); 
}
...

With the ExampleApp the console.log with the try catch shows:

{code:10, error: "DEVELOPER_ERROR"}

This seems to be the lack of a SHA1 in the Firebase Console from my app.

pitakill avatar Jul 28 '17 22:07 pitakill

Same Probelm Here also

trinadhkoya avatar Aug 10 '17 15:08 trinadhkoya

https://github.com/devfd/react-native-google-signin/blob/master/android-guide.md#e-getting-developer_error-error-message-on-android-when-trying-to-login

MikePodgorniy avatar Apr 03 '18 12:04 MikePodgorniy

Even I was facing this issue. You can try something like this


const authorizeWithPermissions = () => {
  const iosClientId = Config.IOS_GOOGLE_CLIENT_ID;
  const androidClientId = Config.ANDROID_GOOGLE_CLIENT_ID;
  const serverClientID = Config.GOOGLE_SERVER_ID;
  let googleSignConfiguration = {
    scopes: ["email", "https://www.googleapis.com/auth/plus.me", "profile", "https://www.googleapis.com/auth/gmail.readonly"],
    clientID: iosClientId,
    serverClientID
  };
  
  if (Platform.OS === "android") {
    googleSignConfiguration = Object.assign({}, googleSignConfiguration, {
      clientID: androidClientId,
      offlineAccess: true
    });
  }
  
  return GoogleSignIn.configure(googleSignConfiguration)
  .then(() => {
    GoogleSignIn.signOut();
    return GoogleSignIn.signInPromise();
  })
  .then((user) => {
    user.ok = true;
    return user;
  })
  .catch(() => {
    const user = {};
    user.ok = false;
    return user;
  });
};
  registerGoogle = () => {
    this.toggleLoader();
    authorizeWithPermissions()
      .then((response) => {
        const {idToken, serverAuthCode, ok} = response;
        if (!ok) {
          this.toggleLoader();
          return;
        }
      .......

      });
  };

salujaharkirat avatar May 31 '18 11:05 salujaharkirat

try use try and catch

ziad784 avatar Nov 27 '20 11:11 ziad784