Skip to content

session persistence doesn't work end to end #390

Description

@fresh55

Two things I ran into while testing with a SessionHandler set up.

First, InitializeAsync() doesn't restore anything. The readme for the Supabase package says it restores and refreshes a persisted session, but it only calls Auth.RetrieveSessionAsync(), which returns early when CurrentSession is null, and nothing in the umbrella client ever calls LoadSession(). So SaveSession and DestroySession get called but LoadSession never does, and after a restart every request goes out with the anon key. Calling supabase.Auth.LoadSession() before InitializeAsync() works around it, same as the gotrue readme shows.

Second, once a session is restored a failed refresh deletes it. The catch in packages/Gotrue/Gotrue/Client.cs treats every exception the same, so a connection error looks identical to gotrue rejecting the refresh token, and it hits DestroySession() on line 669. Starting the app offline with AutoRefreshToken = true goes:

  1. LoadSession() restores the saved session
  2. InitializeAsync()RetrieveSessionAsync() → refresh throws a connection error
  3. the catch calls DestroySession(), the persistence listener fires, session gets wiped from disk

The user stays signed out even once they're back online. Repros against any dead host, point the client at an unused port.

These are linked. Fixing the first on its own would make the second hit everyone by default instead of only the people calling LoadSession themselves.

I can work on this.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions