supabase-community / gotrue-csharp

C# implementation of Supabase's GoTrue
https://supabase-community.github.io/gotrue-csharp/api/Supabase.Gotrue.Client.html
MIT License
39 stars 27 forks source link

Preserve token refresh interval #74

Closed nref closed 1 year ago

nref commented 1 year ago

Fixes https://github.com/supabase-community/gotrue-csharp/issues/73

Before, the first token refresh happened after the configured interval. Then, token refreshes happened every 5s. Now, the configured interval is preserved.

More: The Timer was disposed and recreated on each refresh. This is not necessary. Now the same timer is used for all refreshes.

wiverson commented 1 year ago

FWIW the token refresh every 5 sec is a bug (my bad). The Timer dispose / recreate I did just in case the thread crashed for some reason, but I can see it either way. I'll let @acupofjose put in thoughts but this looks good to me.

nref commented 1 year ago

Thanks Will, and that's a good point about creating a new timer thread. Now that I've thought about it, creating a new thread every, say hour or more is not so bad. Plus this would be a subtle change in behavior. I bet somebody somewhere is already relying on the fact that a new thread will rescue them. I'll put it back the way it was.

nref commented 1 year ago

Put the timer back the way it was.

Extracted new method CreateNewTimer() which is called from InitRefreshTimer() and HandleRefreshTimerTick(...). This adds a hopefully wanted change in refresh behavior: The refresh now also checks for an unexpired session, like only InitRefreshToken() did previously.

Tested working in my supabase client app.