问题
This is my scenario. I am developing a firebase login
iOS app. For this i am using Email & Password Authentication
and facebook authentication
. Lets assume if user knows his email but forgot the password. How can i identify if the user logged in with facebook or email, and how to reset the password? i searched a lot. But could not find a solution for that. can anyone help me.
回答1:
You can lookup the providers linked to an account using: fetchProvidersForEmail
To reset the password, use: sendPasswordResetWithEmail
There are also instructions on how to send the password reset and redirect back to app: https://firebase.google.com/docs/auth/ios/passing-state-in-email-actions
回答2:
Try the following.
- Whenever a user signs up with your platform, be sure to save their basic information e.g.
email
,name
,photoURL
,signup/loginType
,user-id
etc to a database of your choice i.eFirebase Firestore
or theRealtime Database(RTD)
.
So you could have the following Scheme in the RTD
for instance:
my-app
----users
--------user-id-1
------------name: User 1
------------email: user1@domain.com
------------loginType:facebook
------------id: user-id-1
--------user-id-2
------------name: User 2
------------email: user2@domain.com
------------loginType:email
------------id: user-id-2
---etc
This way if a user claims to have forgotten their password, you can do a quick lookup via email and obtain the users id. For the Realtime Database I would recommend denormalize your data a bit more so that you can retrieve user id's by email. This is what I mean
my-app
--users
--------user-id-1
------------name: User 1
------------email: user1@domain.com
------------id: user-id-1
--------user-id-2
------------name: User 2
------------email: user2@domain.com
------------loginType:email
------------id: user-id-2
--users-by-email
--------user1@domain.com
------------user-id-1
--------user2@domain.com
------------user-id-2
In this case you can easily find the users id based on their email if you search the users-by-email field and insert the users email as a key. It should return the userid
.
In Firestore
, I believe you can easily query for this without having to denormalize your data.
- Once you have access to the
users-id
andemail
, you can follow this guide by @JenPerson from the Firebase team on how to mint your own Authentication tokens, that will let Firebase know you are re-authenticating a specified user with different credentials
来源:https://stackoverflow.com/questions/49023909/firebase-forgot-password-how-to-identify-whether-user-signed-in-with-email-or-f