First of all, thank you for the component @devfd.
Works exactly as expected on Android.
Having some issues, probably setup related.
The app terminates with exception "* Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'You must specify |clientID| for |GIDSignIn|'".
I have done all steps as mentioned in iOS guide. This clearly means it still does not find the client ID.
I have also passing CLIENT_ID from GoogleService-Info.plist in GoogleSignIn.configure as iosClientId.
What might I be missing or misinterpreting from the documentation ?
I actually modified the RNGoogleSignin.m as follows by hardcoding the value still get same error.
@devfd , do you think this a version compatibility issue probably ?(I am using RN0.34.1)
//[GIDSignIn sharedInstance].clientID = iosClientId;
[GIDSignIn sharedInstance].clientID = @"my-clientid-from-google.plist.apps.googleusercontent.com";
I managed to get this working.
Earlier structure was to call configure and then do a signin. This worked on Android but not on iOS.
In iOS, I got it to work by moving configure at different location (componentDidMount : which may or may not be the most efficient place) however now it doesn't crash and GoogleSignin.currentUserAsync() works as expected.
Hey,
I am receiving this error. Can you elaborate on your solution or provide code? Not sure if I should move GoogleSignin.configure to componentDidMount before or after GoogleSignin.currentUserAsync
Hi @antoniuschan99, This is how it has worked for me.
Call GoogleSignin.configure in componentDidMount. However here I am checking if(Platform.OS === 'ios') and sending iosClientId as one additional parameter
Calling _setupGoogleSignin() custom function when button is pressed which is declared as async _setupGoogleSignin()
Within async _setupGoogleSignin(), invoke currentUserAsync as const user = await GoogleSignin.currentUserAsync();
Then invoke signIn as GoogleSignin.signIn()
.then((user) => {.....
@bhushanjawle thanks!
@bhushanjawle Hey i cannot seem to solve this issue even with the steps as directed from above. Any way you may be able to further elaborate?
@Mikael491 Here is abbreviated code for your reference. Trust this helps.
For some reason the code formatting below applies only partially so just for clarity, everything below here is code formatted.
`
// Step 1 (mentioned above)
componentDidMount(){
//......Initialization code here if applicable
try{
if(Platform.OS === "ios"){
GoogleSignin.configure({
scopes: ["https://www.googleapis.com/auth/calendar"],
iosClientId:"xxxx",
webClientId: "yyyy",
offlineAccess: true
});
}else if (Platform.OS === "android") {
GoogleSignin.hasPlayServices({ autoResolve: true });
GoogleSignin.configure({
scopes: ["https://www.googleapis.com/auth/calendar"],
webClientId: "yyyy",
offlineAccess: true
});
}
}
catch(err) {
console.log("Google error: ", err.code, err.message);
}
}
// Step 2 : when button is pressed, call custom setup function like so
handleGooglePress = () =>{
//...other UI state management code if required e.g. set animating as true etc.
this._setupGoogleSignin();
}
// Step 3 : Custom function
async _setupGoogleSignin() {
try {
// Step 4 : Custom function
const user = await GoogleSignin.currentUserAsync();
console.log(user);
GoogleSignin.signIn()
.then((user) => {
console.log(user);
// Do what is required for as per your application flow e.g. auto login
.......
})
.catch((err) => {
console.log("WRONG SIGNIN", err);
})
.done();
}
catch(err) {
console.log("Play services error", err.code, err.message);
}
}
`
I've fixed this issue with configuring GoogleSignIn in my App.js like this:
componentDidMount() {
GoogleSignIn.configure({
webClientId: config.webClientId,
offlineAccess: false
})
}
Hope it helps somebody.
Most helpful comment
I've fixed this issue with configuring GoogleSignIn in my App.js like this:
Hope it helps somebody.