Firebase Multiple Accounts are signed at the same time

后端 未结 3 963
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-01-18 06:33

I want my users to sign in with multiple accounts (Not linking multiple providers)

like gmail, it allows you to use multiple signed in accounts at the same time you

3条回答
  •  囚心锁ツ
    2021-01-18 07:33

    I was thinking about this issue, reading through the documentation and found that you can re-authenticate a user by credential. So maybe you can do it this way:

    when a new user wants to sign in you take his info as AuthCredential object like this:

    AuthCredential credential = EmailAuthProvider.getCredential("user@example.com", "password1234");
    //there is also GoogleAuthProvider, FacebookAuthProvider...
    

    then to actually signing him in you use signInWithCredential(AuthCredential) :

    FirebaseUser user = FirebaseAuth.getInstance().signInWithCredential(credential);
    

    Now you need to save the credential object and the user object somewhere safe. If you want to add new user you do the same and save the new objects. After that whenever in your app you want to switch between the users you get that user's object and call reauthenticate(AuthCredential) method:

    myFirstUserObject.reauthenticate(myFirstUserCredential);
    

    I didn't really test this, you think it could work? I don't know exactly how to save the objects and if there is a safe way to implement it without exposing each user's credential?

提交回复
热议问题