Skip to content

Commit 8b1cbb6

Browse files
committed
Merge branch 'master' of https://github.com/supabase/supabase-js
2 parents 7271a06 + 965b409 commit 8b1cbb6

File tree

4 files changed

+12
-3
lines changed

4 files changed

+12
-3
lines changed

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@supabase/supabase-js",
3-
"version": "0.35.7",
3+
"version": "0.35.8",
44
"description": "Supabase Realtime API",
55
"main": "./lib/index.js",
66
"scripts": {

src/Auth.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,10 +124,19 @@ class Auth {
124124

125125
this.removeSavedSession = () => {
126126
this.currentUser = null
127+
this.refreshToken = null
127128
this.accessToken = this.supabaseKey
128129
isBrowser() && localStorage.removeItem(storageKey)
129130
}
130131

132+
this.authHeader = () => {
133+
let json = isBrowser() && localStorage.getItem(storageKey)
134+
let persisted = json ? JSON.parse(json) : null
135+
if (persisted?.accessToken) return `Bearer ${persisted.accessToken}`
136+
else if (this.accessToken) return `Bearer ${this.accessToken}`
137+
else return null
138+
}
139+
131140
this.recoverSession = () => {
132141
const json = isBrowser() && localStorage.getItem(storageKey)
133142
if (json) {

src/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ class SupabaseClient {
9191
initClient() {
9292
let headers = { apikey: this.supabaseKey }
9393

94-
if (this.auth.accessToken) headers['Authorization'] = `Bearer ${this.auth.accessToken}`
94+
if (this.auth.authHeader()) headers['Authorization'] = this.auth.authHeader()
9595

9696
let rest = new PostgrestClient(this.restUrl, {
9797
headers,

0 commit comments

Comments
 (0)