Firebase forgot password- how to identify whether user signed in with email or facebook?

点点圈 提交于 2019-12-08 13:09:45

问题


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.

  1. 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.e Firebase Firestore or the Realtime 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.

  1. Once you have access to the users-id and email, 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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!