Improve login pop-up experience
See original GitHub issueBug, feature request, or proposal:
This is a proposal to improve the login popup experience as described below. Could be considered a bug fix.
What is the expected behavior?
When logging into MachineLabs, a single 0auth provider popup should show up. Right now it’s always two due to the reasons described below.
What is the current behavior?
Notice how two pop-ups appear when logging into ML:
The reason this is happening, is because we first try to link the current user with the (newly created) auth user and only if that operation fails (the auth user for the given oauth provider already exists), we fall back to performing just a login. Between those operations we also create a new node for /users
if needed.
Unfortunately, Firebase doesn’t provide an API that checks whether an auth user already exists or not. That’s why we always try to link the current (possibly anonymous) user first and only if that fails, we know the user already exists so we can simply login. If we’d try to login right away without trying to link the auth user first, the login will always fail as no auth user exists, which means no user will be able to login to MachineLabs.
The consequence of this is that we perform two operations for the login, resulting in two pop-ups (That’s also why for the very first login every made [where the auth user creation is successful], there’s only a single popup, because users are then automatically signed in).
What are the steps to reproduce?
If you have an ML account, login.
What is the use-case or motivation for changing an existing behavior?
This is obviously not a show stopper but definitely something we’d like to iron out at some point.
Is there anything else we should know?
I talked to other firebase devs to figure out how they handle such a scenario, especially because it’s so common. It turns out it’s the job of the developer to figure out how to handle this. One common approach is to create a dedicated users
node, where created auth users are being added to. Then, when logging in, one would first perform a request to check whether that user exists in /users
and then decide whether to perform linkWithPopup()
or signInWithPopup()
right away.
We already have this /users
node, but we’d still need to figure out for what users to check against. Obviously, that’d be for example the github provider data email address, but that one we’re getting from the first popup that we’re trying to get rid off. Happy to discuss ideas here.
Here’s the code affected by this:
Basically the flow right now is like this:
-> login
-> try to link current user with provider user (github)
-> fall back to just signing in, in case auth user is already link/authenticated
-> if user has been linked/authenticated for the first time, create new node in /users
loginWithGithub()
- used to perform loginlinkOrSignInWithGithub()
- tries to link/authenticated current user with auth users and falls back to signing in with GitHub, if the user is already permantly linkedcreateUserIfMissing()
- Once linked or signed in, we create a/users
node if necessary
Issue Analytics
- State:
- Created 5 years ago
- Comments:7 (7 by maintainers)
Top GitHub Comments
This has been fixed with https://github.com/machinelabs/machinelabs/commit/45797a175197d9ef8724b94e342c3542653c0bb9
Woot!