I'm using the GIDSignInButton
to sign my users into Google. Problem is, I'm not sure how to save the current user so that each user doesn't have to sign in every time they open the app. I've tried using signInSilently()
but I get The operation couldn’t be completed. (com.google.GIDSignIn error -4.)
every time.
That error, in the header file, says this :
// Indicates there are no auth tokens in the keychain. This error code will be returned by
// signInSilently if the user has never signed in before with the given scopes, or if they have
// since signed out.
kGIDSignInErrorCodeHasNoAuthInKeychain = -4,
In my case, the user has already signed in with the given scopes, and they have not signed out yet. So I'm not sure what could be causing that error.
After a user signs in, how should I save that instance where I'm able to use signInSilently()
after that? Is there handling involved with the refresh and access tokens as well?
Are you sure you have not user signed out or even disconnected somewhere?
I'm always checking whether the user has either currently signed in or has previous authentication saved in using hasAuthInKeychain
(e.g. in viewWillAppear
):
private func checkIfGoogleUserIsAuthorized() {
if GIDSignIn.sharedInstance().hasAuthInKeychain() {
// User was previously authenticated to Google. Attempt to sign in.
GIDSignIn.sharedInstance().signInSilently()
} else {
// User was not previously authenticated to Google.
self.updateUI()
}
}
In case there is no authentication saved, you must trigger silent sign in and handle reply with your implementation of GIDSignInDelegate
protocols didSignInForUser
method.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With