Firebase Multiple Accounts are signed at the same time

后端 未结 3 959
爱一瞬间的悲伤
爱一瞬间的悲伤 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:19

    Multiple simultaneous logins in the same project is not supported with Firebase Auth.

    You could possibly have multiple logins between multiple projects if you manually initialize the Firebase SDK with the settings for the other projects.

    0 讨论(0)
  • 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?

    0 讨论(0)
  • 2021-01-18 07:35

    From one project, no i don't think you can have two users signed in.

    You can create another Firebase project and add your app there (you'll be able to add your sha-1 on either one). You can then look up their approach to using two Firebase projects in one app.

    You'll be able to sign in with two users in this way if there are two projects to sign in with. You'll have to manage your users across both the databases on your own i.e same user will have to have an account with same credentials made in both the projects.

    It's complicated but it can be done. I use anonymous sign in from two separate projects simultaneously in my app, both users are the same... Just their projects are different.

    0 讨论(0)
提交回复
热议问题