Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 1 addition & 12 deletions Gotrue/Client.cs
Original file line number Diff line number Diff line change
Expand Up @@ -595,21 +595,13 @@ public async Task<Session> SetSession(string accessToken, string refreshToken, b
if (CurrentSession == null)
return null;

// Check to see if the session has expired. If so go ahead and destroy it.
if (CurrentSession != null && CurrentSession.Expired())
{
_debugNotification?.Log($"Loaded session has expired");
DestroySession();
return null;
}

// If we aren't online, we can't refresh the token
if (!Online)
{
throw new GotrueException("Only supported when online", Offline);
}

// We have a session, and hasn't expired, and we seem to be online. Let's try to refresh it.
// We have a session, and we seem to be online. Let's try to refresh it.
if (Options.AutoRefreshToken && CurrentSession?.RefreshToken != null)
{
try
Expand Down Expand Up @@ -712,9 +704,6 @@ public async Task RefreshToken()
if (CurrentSession == null || string.IsNullOrEmpty(CurrentSession?.AccessToken) || string.IsNullOrEmpty(CurrentSession?.RefreshToken))
throw new GotrueException("No current session.", NoSessionFound);

if (CurrentSession!.Expired())
throw new GotrueException("Session expired", ExpiredRefreshToken);

var result = await _api.RefreshAccessToken(CurrentSession.AccessToken!, CurrentSession.RefreshToken!);

if (result == null || string.IsNullOrEmpty(result.AccessToken))
Expand Down