supertokens / supertokens-website

Frontend SDK for SuperTokens - for session management + automatically refreshing sessions
https://supertokens.com
Other
54 stars 13 forks source link

Is UNAUTHORISED event firing correctly? #73

Closed rishabhpoddar closed 3 years ago

rishabhpoddar commented 3 years ago

An instance of when we fire them is if after getting the refresh lock, and if the session doesn't exist, then we fire it. This may not be correct (see fetch.ts, line 357)

porcellus commented 3 years ago

I'll look for a better place to fire this event, but a quick and easy solution seems to be to add a property to the event that would show if the current call removed the token. This way, both use cases would get the information necessary:

rishabhpoddar commented 3 years ago

I don't quite understand the hacky solution. Perhaps elaborate a bit more:

porcellus commented 3 years ago

It's not really hacky; it's more of a workaround.

rishabhpoddar commented 3 years ago

Let's discuss this over a call. I am still unclear about what you are trying to say.

porcellus commented 3 years ago

I propose calling this property sessionExpiredOrRevoked, but we should make it explicit that this only happens in one tab (once per session). removingSession would be more accurate, but it doesn't tell the user how to react to this event.

The cases we the "UNAUTHORISED" event is:

  1. We never had a session but tried calling an endpoint that requires one.
  2. We thought we had a session, but it was removed before we could try to refresh it (likely another process tried and failed)
  3. After a 401, the frontend thought it had a session but could not refresh it. This indicates that the session expired or was revoked on the server and this is the first the frontend notices.

Cases 1&2 can occur many times, but 3 can only happen once per session, and as far as I can tell, this is the one we want to separate. We could indicate something along the lines of hadSession or triedRefreshing, but that would not be too useful.

rishabhpoddar commented 3 years ago

The code changes look good. Please do docs modification for the same.

rishabhpoddar commented 3 years ago

@porcellus we also need to update the onHandleEvent type in the auth-react SDK as that doesn't have the extra boolean along with the UNAUTHORISED action.