Skip to content

Conversation

@grdsdev
Copy link
Contributor

@grdsdev grdsdev commented Nov 10, 2025

Description

Fixes #1261

This PR removes the redundant check that required currentSession.accessToken to exist before allowing a session refresh.

Problem

The refreshSession method was throwing an AuthSessionMissingException when there was no current session, even if a valid refreshToken was provided as a parameter. This blocked a valid use case where you might have a refresh token but no current session.

Solution

  • Removed the redundant check for currentSession?.accessToken == null
  • The existing null check for the refresh token (currentSessionRefreshToken == null) is sufficient to handle both cases:
    • When a refreshToken parameter is provided
    • When falling back to _currentSession?.refreshToken
  • Updated documentation to clarify the behavior
  • Improved error message to be more accurate
  • Added test to verify the fix works correctly

Changes

  • packages/gotrue/lib/src/gotrue_client.dart: Removed redundant check, updated docs
  • packages/gotrue/test/client_test.dart: Added test for refreshSession with refreshToken when no current session exists

Testing

  • ✅ Added unit test that verifies refreshSession(refreshToken) works when currentSession is null
  • ✅ All existing tests should continue to pass (backward compatible)
  • ✅ No linter errors

…ession exists

Remove redundant check that required currentSession.accessToken to exist.
The method now correctly works when a refreshToken is provided as a
parameter, even if there's no current session. The existing null check
for the refresh token is sufficient to handle both cases.

Fixes #1261
@grdsdev grdsdev requested review from a team, Vinzent03 and dshukertjr November 10, 2025 14:02
@grdsdev grdsdev merged commit 1d142c1 into main Nov 10, 2025
15 checks passed
@grdsdev grdsdev deleted the guilherme/sdk-514-refreshsession-shouldnt-fail-because-currentsession-doesnt branch November 10, 2025 16:12
@coveralls
Copy link

Pull Request Test Coverage Report for Build 19234218247

Warning: This coverage report may be inaccurate.

This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.

Details

  • 0 of 1 (0.0%) changed or added relevant line in 1 file are covered.
  • 1 unchanged line in 1 file lost coverage.
  • Overall coverage increased (+0.01%) to 79.691%

Changes Missing Coverage Covered Lines Changed/Added Lines %
packages/gotrue/lib/src/gotrue_client.dart 0 1 0.0%
Files with Coverage Reduction New Missed Lines %
packages/gotrue/lib/src/gotrue_client.dart 1 62.02%
Totals Coverage Status
Change from base Build 18568213555: 0.01%
Covered Lines: 3300
Relevant Lines: 4141

💛 - Coveralls

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

refreshSession shouldn't fail because currentSession doesn't exists if the refreshToken is provided

4 participants