Skip to content

Commit f0eb084

Browse files
committed
feat: add suppressGetSessionWarning option to suppress server-side warnings
- Add suppressGetSessionWarning property to GoTrueClientSettings type - Initialize suppressGetSessionWarning in GoTrueClient constructor - Add test case to verify warning suppression works correctly - Mark as experimental feature in JSDoc comments
1 parent e658156 commit f0eb084

3 files changed

Lines changed: 36 additions & 0 deletions

File tree

src/GoTrueClient.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ const DEFAULT_OPTIONS: Omit<
128128
flowType: 'implicit',
129129
debug: false,
130130
hasCustomAuthorizationHeader: false,
131+
suppressGetSessionWarning: false,
131132
}
132133

133134
async function lockNoOp<R>(name: string, acquireTimeout: number, fn: () => Promise<R>): Promise<R> {
@@ -234,6 +235,7 @@ export default class GoTrueClient {
234235
this.detectSessionInUrl = settings.detectSessionInUrl
235236
this.flowType = settings.flowType
236237
this.hasCustomAuthorizationHeader = settings.hasCustomAuthorizationHeader
238+
this.suppressGetSessionWarning = settings.suppressGetSessionWarning
237239

238240
if (settings.lock) {
239241
this.lock = settings.lock

src/lib/types.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,11 @@ export type GoTrueClientOptions = {
9595
* @experimental
9696
*/
9797
hasCustomAuthorizationHeader?: boolean
98+
/**
99+
* Set to "true" if you want to suppress the warning when getting a session in server side environments.
100+
* @experimental
101+
*/
102+
suppressGetSessionWarning?: boolean
98103
}
99104

100105
export type WeakPasswordReasons = 'length' | 'characters' | 'pwned' | (string & {})

test/GoTrueClient.test.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1694,6 +1694,35 @@ describe('GoTrueClient with storageisServer = true', () => {
16941694
expect(warnings.length).toEqual(0)
16951695
})
16961696

1697+
test('getSession emits no warnings when suppressGetSessionWarning is set to true', async () => {
1698+
const storage = memoryLocalStorageAdapter({
1699+
[STORAGE_KEY]: JSON.stringify({
1700+
access_token: 'jwt.accesstoken.signature',
1701+
refresh_token: 'refresh-token',
1702+
token_type: 'bearer',
1703+
expires_in: 1000,
1704+
expires_at: Date.now() / 1000 + 1000,
1705+
user: {
1706+
id: 'random-user-id',
1707+
},
1708+
}),
1709+
})
1710+
storage.isServer = true
1711+
1712+
const client = new GoTrueClient({
1713+
storage,
1714+
suppressGetSessionWarning: true,
1715+
})
1716+
1717+
const {
1718+
data: { session },
1719+
} = await client.getSession()
1720+
1721+
const user = session?.user // accessing the user object from getSession shouldn't emit a warning
1722+
expect(user).not.toBeNull()
1723+
expect(warnings.length).toEqual(0)
1724+
})
1725+
16971726
test('saveSession should overwrite the existing session', async () => {
16981727
const store = memoryLocalStorageAdapter()
16991728
const client = new GoTrueClient({

0 commit comments

Comments
 (0)