Replies: 3 comments 13 replies
-
Not sure why this is the case, sounds like a bug in Firebase. If public async restore() {
const user = await super();
const token = await getIdTokenResult(user, true);
return { authUser: user, token };
} This is just me thinking out loud, not sure if this would work on your case and remove the infinite loop. |
Beta Was this translation helpful? Give feedback.
-
Thanks @mikkopaderes, I'm going to spend some time today digging into it a bit deeper. If you have time, it would be helpful to understand a bit more about your implementation. In particular, I'd like to understand what is intended by setting up the
Given |
Beta Was this translation helpful? Give feedback.
-
@mikkopaderes I've made a minimal reproduction here: https://github.com/roomman/bughunt-ember-auth-restore-loop I've included notes in the README but, in summary, if you have two or more browser sessions open and authenticate in one the others try to restore and fail. On the second attempt, it succeeds but then the This is using your default authenticator, so I believe this affects all users of this repo. In terms of the cause, the working hypothesis is that the user passed into Any thoughts on what might be causing this? |
Beta Was this translation helpful? Give feedback.
-
Hi, I'm looking for a steer regarding how folk are dealing with Auth user tokens and custom claims in their apps.
Over the weekend I identified a bug in our app, whereby opening two browser sessions caused the
restore()
method in our custom authenticator to fire in a recursive loop. The culprit was some code we'd added into our authenticator to refresh the user token so we could capture any changes to a user's claims, those being fundamental to our Firestore security rules.To fix this issue, we had to revert back to the original authenticator (the one provided by the addon) and create a service which polls the Auth user's token for changes, and updates the local session as required. This works but it seems like there would be a better way.
Can anyone shed some light and share their own approach to managing user claims?
Update
I'm just padding this question out with a bit more background and context, in case anyone has time to share their experiences.
Our
ember-simple-auth
custom authenticator is a very subtle modification of the base provided by this repo, and looks like this:The key difference is that we are returning the deserialised copy of the user's
idToken
along with the user.We need this token so that we can manage access control by checking Custom Claims. For example:
The issue I'm having is how we refresh that token, as and when the claims change. For example, if we removed admin permissions from a user.
When manually calling
this.session.session.restore()
using the above Authenticator, we just get the local copy of the token with the expired claims. If I modifyrestore
so thatconst token = await getIdTokenResult(user, true)
(we are now forcing a refresh) I get a fresh token from the server along with the new claims. However, if I open a second browser tab,restore()
/onAuthStateChanged
is called in an infinite loop.As a workaround, I created a service that gets a fresh token every fifteen minutes, compares the old and new claims, and calls
this.session.session.restore()
if changes are found. This results inrestore()
being fired ~40 times per browser session.Is anyone else managing their tokens within their Authenticator? Can you share your approach?
If you think I'm mad and should be taking a totally different approach, please say 🤣
Beta Was this translation helpful? Give feedback.
All reactions