You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: src/lib/helpers.ts
+21-1
Original file line number
Diff line number
Diff line change
@@ -1,5 +1,5 @@
1
1
import{API_VERSION_HEADER_NAME}from'./constants'
2
-
import{SupportedStorage}from'./types'
2
+
import{SupportedStorage,User}from'./types'
3
3
4
4
exportfunctionexpiresAt(expiresIn: number){
5
5
consttimeNow=Math.round(Date.now()/1000)
@@ -344,3 +344,23 @@ export function parseResponseAPIVersion(response: Response) {
344
344
returnnull
345
345
}
346
346
}
347
+
348
+
exportfunctionuserNotAvailableProxy(): User{
349
+
returnnewProxy({}asUser,{
350
+
get: (_target: any,prop: string)=>{
351
+
thrownewError(
352
+
`@supabase/auth-js: client was created with userStorage option and there was no user stored in the user storage. Accessing the "${prop}" property of the session object is not supported. Please use getUser() instead.`
353
+
)
354
+
},
355
+
set: (_target: any,prop: string)=>{
356
+
thrownewError(
357
+
`@supabase/auth-js: client was created with userStorage option and there was no user stored in the user storage. Setting the "${prop}" property of the session object is not supported. Please use getUser() to fetch a user object you can manipulate.`
358
+
)
359
+
},
360
+
deleteProperty: (_target: any,prop: string)=>{
361
+
thrownewError(
362
+
`@supabase/auth-js: client was created with userStorage option and there was no user stored in the user storage. Deleting the "${prop}" property of the session object is not supported. Please use getUser() to fetch a user object you can manipulate.`
Copy file name to clipboardexpand all lines: src/lib/types.ts
+12
Original file line number
Diff line number
Diff line change
@@ -69,6 +69,14 @@ export type GoTrueClientOptions = {
69
69
persistSession?: boolean
70
70
/* Provide your own local storage implementation to use instead of the browser's local storage. */
71
71
storage?: SupportedStorage
72
+
/**
73
+
* Stores the user object in a separate storage location from the rest of the session data. When non-null, `storage` will only store a JSON object containing the access and refresh token and some adjacent metadata, while `userStorage` will only contain the user object under the key `storageKey + '-user'`.
74
+
*
75
+
* When this option is set and cookie storage is used, `getSession()` and other functions that load a session from the cookie store might not return back a user. It's very important to always use `getUser()` to fetch a user object in those scenarios.
76
+
*
77
+
* @experimental
78
+
*/
79
+
userStorage?: SupportedStorage
72
80
/* A custom fetch implementation. */
73
81
fetch?: Fetch
74
82
/* If set to 'pkce' PKCE flow. Defaults to the 'implicit' flow otherwise */
@@ -252,6 +260,10 @@ export interface Session {
252
260
*/
253
261
expires_at?: number
254
262
token_type: string
263
+
264
+
/**
265
+
* When using a separate user storage, accessing properties of this object will throw an error.
0 commit comments