strnmn
strnmn

Reputation: 565

Checking if a user already signed up

I built a custom authentication system using FirebaseAuthentication tokens.

My signup / login flow should work like this:

  1. User presses login button
  2. My server generates the authentication token and sends it to the client
  3. Check if the user already exists (in the 'Auth' table or in my database?)
    • If true: sign in using FIRAuth.auth()?.signIn(withCustomToken:...
    • If false: Show a form to to enter custom information (name, etc..)
      • sign using FIRAuth.auth()?.signIn(withCustomToken:...
      • save the custom information to my database

My question is: How can I find out if the user has already signed up? Would a publicly accessible database with only uid's be the way to go?

Upvotes: 1

Views: 506

Answers (2)

Willjay
Willjay

Reputation: 6459

The firebase sign in method will feedback in asynchronous callback.

FIRAuth.auth()?.signInWithEmail(email, password: password, completion: { (user , error) in
    if let error = error {
        print(error.localizedDescription)
        return
    }
    self.signedIn(user)
})

If you haven't sign up yet. The error will print out

There is no user record corresponding to this identifier. The user may have been deleted.

Upvotes: 0

TheValyreanGroup
TheValyreanGroup

Reputation: 3599

This is fairly opinion based, but yes, I would use a standalone DB that stores each user's username who has signed up. Then all that is required is a quick web request through a PHP file querying for any rows returned with that username.

Upvotes: 2

Related Questions