Skip to content
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
17 changes: 14 additions & 3 deletions src/SupabaseClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -301,10 +301,21 @@ export default class SupabaseClient<
if (this.accessToken) {
return await this.accessToken()
}

const { data } = await this.auth.getSession()

return data.session?.access_token ?? this.supabaseKey

// If no session exists, check for global Authorization header or fall back to supabaseKey
if (!data.session?.access_token) {
// Prefer global.headers.Authorization if explicitly set
const authHeader = this.headers['Authorization'] || this.headers['authorization']
if (authHeader) {
return authHeader.startsWith('Bearer ') ? authHeader.replace('Bearer ', '') : authHeader
}
// Otherwise, use supabaseKey (service role key)
return this.supabaseKey
}

return data.session.access_token
}

private _initSupabaseAuthClient(
Expand Down