ember-cloud-firestore-adapter
ember-cloud-firestore-adapter copied to clipboard
[WIP] Fix auth infinite loop with multi-tabs
Hi @mikkopaderes, you may already have spotted this issue but I was playing about with the "cherryPicker" idea today, using the latest commit on this PR.
public async restore(): Promise<AuthenticatedData> {
return new Promise((resolve, reject) => {
const auth = getAuth();
const unsubscribe = onAuthStateChanged(
auth,
async (user) => {
unsubscribe();
if (user) {
resolve({ user: parseCherryPickedUser(user) });
} else {
getRedirectResult(auth)
.then((credential) => {
if (credential) {
resolve({ user: credential.user });
} else {
reject();
}
})
.catch(() => {
reject();
});
}
},
() => {
unsubscribe();
reject();
}
);
});
}
I opened a session and logged in fine. I then opened two additional tabs on the same route. I logged out in one and all three sessions were invalidated. Then I attempted to login again but that was immediately invalidated by the others. I tried again and all three sessions fired up.
I logged everything out and discovered that on the initial attempt, onAuthStateChanged
and getRedirectResult
in the second and third sessions is returning null
, so the promise is rejected.
@roomman yeah, noticed that which is what's keeping this PR from being merged. There's some relevant info here so I'm trying to see if that would work for us.