JWT expired not being renewed #51
-
I noticed a problem with the session in the Blazor template. It happens when I login and close the app. After the JWT expiry time, I open the app again and it not set the session to not logged in. I realize that, maybe I need to verify if that token is expired inside the SessionRetriever method and return null if it is expired. So, I implemented that. But doing this I noticed that the field CreatedAt has it's set operator private. This way a managed to create another Session class like the Session of the API, and implemented the verification like this:
My doubt is that this implementation is correct or not. I don't have for sure, but if the CreatedAt field has a private set, like this below, when it is instantiated it will always be DateTime.Now, it never will be the value retrieved from the cookie.
I implemented it in my fork: |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Ooo my. That's a fantastic catch! I'll make a quick change and push an update to gotrue-csharp. But you're correct, ideally the session would be validated by the retriever before being returned. Gotrue-csharp will take the returned session and attempt to refresh it's token and everything. This will fail if the session is invalid. The easiest way to do it (IMO) is to do The |
Beta Was this translation helpful? Give feedback.
Ooo my. That's a fantastic catch! I'll make a quick change and push an update to gotrue-csharp.
But you're correct, ideally the session would be validated by the retriever before being returned. Gotrue-csharp will take the returned session and attempt to refresh it's token and everything. This will fail if the session is invalid.
The easiest way to do it (IMO) is to do
isValid = await Supabase.Auth.GetUser(savedSession.Token)
(you get the idea). Or you can check theCreatedAt
vs. theExpiredAt
.The
CreatedAt
not being set correctly does produce issues with the token being automatically refreshed - so this update will fix that!