Skip to content

fix: initialize auth subclient with auth key token#53

Open
zugdev wants to merge 1 commit into
supabase-community:mainfrom
zugdev:fix/auth-token-initialization
Open

fix: initialize auth subclient with auth key token#53
zugdev wants to merge 1 commit into
supabase-community:mainfrom
zugdev:fix/auth-token-initialization

Conversation

@zugdev

@zugdev zugdev commented Mar 29, 2026

Copy link
Copy Markdown

What kind of change does this PR introduce?

Bug fix, resolves #16

What is the current behavior?

NewClient() creates the Auth subclient but never calls WithToken(). The auth-go internal newRequest() only sends Authorization: Bearer when the token field is non-empty, so the header is omitted (silently). Thus, any call to authenticated endpoints returns a 401.

What is the new behavior?

Chain .WithToken(key) onto the Auth client initialization.

supabase-py does this in _sync/client.py line 325:

authorization = self.options.headers.get(
    "Authorization", self._create_auth_header(self.supabase_key)
)

Introduce TestGetUserSendsAuthHeader (which is also a PoC of the previous behavior) verifies the header is sent using an httptest mock server.

Additional context

One-line change in client.go. No breaking changes.

NewClient() creates the Auth sub-client via auth.New() but never calls
WithToken(), so the Auth sub-client's internal requests lack the
Authorization header. Chain .WithToken(key) in the initialization to
match supabase-py's behavior where the API key serves as the initial
bearer token until a user signs in.

Fixes supabase-community#16
@zugdev zugdev changed the title fix: initialize auth sub-client with API key token fix: initialize auth subclient with auth key token Mar 29, 2026
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.

Auth is not intialised with User Token

1 participant