Reputation: 21
I created an iOS app with Firebase. So when I launch the app, it ask me to login or register, so that is what I expected. However I would like to "save" the authenticate because when I close and reopen the app I would like to avoid the login page.
Is it possible for an iOS app built with Firebase to "remember" that the user has already log in even before he closed the app?
Upvotes: 1
Views: 562
Reputation: 21
Finally thanks to Frank van Puffelen I implemented this code :
override func viewDidAppear(_ animated: Bool) {
if Auth.auth().currentUser != nil {
// User is signed in.
performSegue(withIdentifier: "goToHome", sender: self)
} else {
// No user is signed in.
// ...
}
}
Because performSegue() does not perform in viewDidLoad()
Upvotes: 0
Reputation: 598765
Firebase automatically persists information about the authenticated user. When the user restarts the app, that information is read and (if possible) its authentication state is restored.
To detect this authentication state you'll need to implement an auth state listener as shown in the documentation on getting the currently signed in user:
handle = Auth.auth().addStateDidChangeListener { (auth, user) in
// ...
}
Upvotes: 0
Reputation: 706
Take a flag login. when you successfully logged in then make it true.login = true
and then update your AppDelegate.swift file i.e. if login true then it will show your desired view.
Upvotes: 1