-
-
Notifications
You must be signed in to change notification settings - Fork 37
Callback of onAuthStateChange()
is not called when recoverSession()
is used
#17
Comments
@kaboc, there is an issue with session recovery timer. I fixed it on the latest version let me know if you still facing the issue. |
@phamhieu However, it wasn't called when Is the session recovery timer you mentioned related to expiration of a token/session? I think my last sign-in to the app was yesterday or the day before, so it is likely that the session had already expired at the point of my first attempt today. I hope this gives you a clue. |
recoverSession will only trigger an event if the current session is invalid and it refresh to a new one In your case, can check your access token expiry to confirm? Can you also test on a fresh install to ensure that the persistent session value is right. The timer bug is because of invalid expiryAt persistent session value. P.S if you want to force a refresh, then you should call auth.api.refreshAccessToken instead |
@phamhieu I think it is reasonable, but What is more confusing is that it is triggered even on recovery if the access token has already expired.
I think this could be improved for better usability. I actually expected that I could write only once inside the callback the code for navigating a user after sign-in and recovery, but I'll write it separately as a workaround if it's not possible. |
It is also what I'm not sure about. It looks like the token expires if I don't use an app for a while after launching it. I notice the expiry only when a query to the database fails.
I would be grateful if you'd direct me to a related document/thread/issue. |
Totally agree with you. We need to improve the document.
i just update flutter demo app for Supabase. You can take a look as reference https://github.com/phamhieu/supabase-dart-demo.
The default value for token expiry is 3600 seconds (1 hour). If you don't use the app for 1 hour, it will expire. You can update this value if you want (under Authentication settings). There are many ways to solve this. Exp: you can listen for resume event with
there's a bug with gotrue-dart library which causes wrong expiry calculation check.
no, you don't need. gotrue-dart has a timer to auto refresh the token. here I hope this helps, let me know if you need any other clarification. |
Thanks for all the detailed info, @phamhieu! It'll be helpful for other people too.
I didn't know of the demo app. I'll look into it.
It must be the bug you fixed yesterday, right? I left my app (with supabase
If the expiry-related issue was fixed, I wonder if you still need to listen for the resume event. The token does not expire while you keep using the app, so recovery is only needed when the app is launched, but AFAIK the state does not change to Now that you clarified that the behaviour I thought was a bug was actually an expected behaviour, you can close this issue once documentation is improved. Thank you! |
the token will not expire if app runs on foreground. Listening for the resume event will help recover session when app resumes from background state. I have an example here |
Bug report
Describe the bug
Calling
recoverSession()
results in changing the auth state if the recovery is successful, so I thought the callback function ofonAuthStateChange()
would be called, but it actually wasn't.To Reproduce
Expected behavior
"AuthChangeEvent.signedIn" is printed in the console when the user's sign-in state is recovered by
recoverSession()
.I’m not really sure if this is the right behaviour as it is not documented in the API reference of the package. Therefore it is just what I personally expected to happen.
System information
The text was updated successfully, but these errors were encountered: