I have implemented a Google SignIn with Firebase in my iOS app, following the Firebase guide. The problem is that every time I test the login, it always asks for permissions.
Here is the code of AppDelegate involved in Google SignIn:
class AppDelegate: UIResponder, UIApplicationDelegate, GIDSignInDelegate {
var window: UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey : Any]? = nil) -> Bool {
// Override point for customization after application launch.
FIRApp.configure()
GIDSignIn.sharedInstance().clientID = FIRApp.defaultApp()?.options.clientID
GIDSignIn.sharedInstance().delegate = self
return true
}
func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool {
return GIDSignIn.sharedInstance().handle(url, sourceApplication: options[UIApplicationOpenURLOptionsKey.sourceApplication] as? String, annotation: options[UIApplicationOpenURLOptionsKey.annotation])
}
func sign(_ signIn: GIDSignIn!, didSignInFor user: GIDGoogleUser!, withError error: Error!) {
if let error = error {
print(error.localizedDescription)
return
}
print("Logged in with Google successfull")
// ... Firebase authentication ...
}
}
And here the code of View Controller with GIDSignInButton:
import UIKit
class IntroViewController: UIViewController, GIDSignInUIDelegate {
@IBOutlet weak var signInButton: GIDSignInButton!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
GIDSignIn.sharedInstance().uiDelegate = self
signInButton.style = .wide
}
}
I've searched a lot on the web but found nothing... So, how can I prevent to ask for permission every time?
firebase.auth.Auth.Persistence.SESSION. 'session' Indicates that the state will only persist in the current session or tab, and will be cleared when the tab or window in which the user authenticated is closed. Applies only to web apps.
In the Firebase console, open the Auth section. On the Sign in method tab, enable the Google sign-in method and click Save.
If you'd like to sign the user out of their current authentication state, call the signOut method: import auth from '@react-native-firebase/auth'; auth() . signOut() .
I believe this is working as intended. The issue is that you're signing out the user when you're testing your app, and the Google Sign-in library makes the assumption that if a user has explicitly signed out of your app, it should ask that user for permission again before signing that user in.
If you don't explicitly sign out the user, both signIn()
calls and signInSilently()
calls should succeed without displaying any kind of sign-in screen.
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