Skip to content

Fix tokens not refreshing when calling RefreshToken() or RetrieveSessionAsync()#109

Open
pBlackCreek wants to merge 1 commit into
supabase-community:masterfrom
pBlackCreek:master
Open

Fix tokens not refreshing when calling RefreshToken() or RetrieveSessionAsync()#109
pBlackCreek wants to merge 1 commit into
supabase-community:masterfrom
pBlackCreek:master

Conversation

@pBlackCreek

Copy link
Copy Markdown

What kind of change does this PR introduce?

Removed the expiry checks from RefreshToken() and RetrieveSessionAsync() to fix tokens not refreshing when access token is expired.

What is the current behavior?

When RetrieveSessionAsync() is called the expiry is checked and assumes that the session is invalid.
The same check happens in RefreshToken() before actually trying to refresh it, causing it to never properly try to refresh the tokens.

What is the new behavior?

If the access token has expired and AutoRefreshToken is enabled RetrieveSessionAsync() wil try to refresh the tokens.
And when manually calling RefreshToken() the method will continue to refresh the token

Additional context

It seems like it was assumed that the expiry was for the whole session, but it is specifically for the access token.

This would close issue #108 and PR #106

@mcombalia

Copy link
Copy Markdown

I think there is also a problem in the TokenRefresh, were the client signsout the user in the refresh token function, by checking the access token expiry date instead:


private void CreateNewTimer()
		{
			if (_client.CurrentSession == null || _client.CurrentSession.ExpiresIn == default)
			{
				if (Debug)
					_client.Debug($"No session, refresh timer not started");
				return;
			}

			if (_client.CurrentSession.Expired())
			{
				if (Debug)
					_client.Debug($"Token expired, signing out");
				// TODO: CHECK THIS COULD BE WRONG
				// _client.NotifyAuthStateChange(SignedOut);
				return;
			}

			try
			{
				TimeSpan interval = GetInterval();
				_refreshTimer?.Dispose();
				_refreshTimer = new Timer(HandleRefreshTimerTick, null, interval, Timeout.InfiniteTimeSpan);

				if (Debug)
					_client.Debug($"Refresh timer scheduled {interval.TotalMinutes} minutes");
			}
			catch (Exception e)
			{
				if (Debug)
					_client.Debug($"Failed to initialize refresh timer", e);
			}
		}

@Tr00d

Tr00d commented Jul 3, 2026

Copy link
Copy Markdown

@pBlackCreek I'm the new maintainer of the Supabase C# SDK.
It seems this issue as been fixed, but I don't see any release for it.
Give me some time to settle, and I'll get back to you. Thanks!

@Tr00d Tr00d self-requested a review July 3, 2026 14:17
@Tr00d Tr00d self-assigned this Jul 3, 2026
@Tr00d Tr00d added the bug Something isn't working label Jul 3, 2026
@azegallo

azegallo commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

@pBlackCreek I'm the new maintainer of the Supabase C# SDK.

It seems this issue as been fixed, but I don't see any release for it.

Give me some time to settle, and I'll get back to you. Thanks!

@Tr00d my PR that was merged has addressed this. Let me know if you need any help

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants