boldviper
boldviper

Reputation: 11

Keeping a User Logged in with Firebase (Custom iOS Authentication)

We are new programmers trying to develop a meeting app based on google maps. And we are constantly researching and trying to learn swift coding and Xcode. Now we've put together a login system using Firebase and it's Auth features and our app currently is able to create a new user and save it to Firebase database and then the user can log into their account. This is, as we see it, a very basic authenticator function.

Now we want to be able to keep the user logged in after signing up in a fashion like Instagram and some other apps have (Logging in once and then not being asked to log in again until the user signs out explicitly.) We've done some research about these methods and learned about the existence of "sessions" and "Login Tokens" but it seems like every database/app combination requires a different kind of approach.

We want to know what kind of options do we have to keep track of a user property within the rest of the app, like a constant that applies and that can be called from all of our codes and what could we do to implement a one time login function using swift and firebase/firestore combination?

Also we are new to Stackoverflow so hello everyone and we are sorry if we asked a previously asked question.

We wish everyone easy coding!

Upvotes: 1

Views: 1009

Answers (1)

Di Nerd Apps
Di Nerd Apps

Reputation: 818

If you are using Firebase then you could use the Auth module it comes with import FirebaseAuth.

in your override viewDidAppear() you can add the check below and provide functionality

override viewDidAppear(){
super.viewDidAppear()
if Auth.auth().currentUser != nil {
  // User is signed in.
  // ...
} else {
  // No user is signed in.
  // ...
}}

if you want to get the currentUID for the user that was set by Firebase you can also use guard let uid = Auth.auth().currentUser?.uid else{return}

Upvotes: 1

Related Questions