Skip to content

Commit 2ff5773

Browse files
authored
Merge pull request #7544 from sreeisalso/supabase-ssr
Supabase ssr update
2 parents 274d038 + d4c403e commit 2ff5773

File tree

9 files changed

+3001
-2584
lines changed

9 files changed

+3001
-2584
lines changed

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,8 +183,7 @@
183183
"pnpm": {
184184
"overrides": {
185185
"typescript": "5.4.5",
186-
"vfile": "6.0.2",
187-
"@supabase/realtime-js": "2.8.4"
186+
"vfile": "6.0.2"
188187
},
189188
"patchedDependencies": {
190189

packages/docs/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
"@shikijs/rehype": "3.1.0",
2424
"@shikijs/transformers": "3.1.0",
2525
"@shikijs/types": "3.1.0",
26-
"@supabase/supabase-js": "2.44.4",
26+
"@supabase/supabase-js": "2.49.4",
2727
"@tailwindcss/vite": "4.0.12",
2828
"@types/leaflet": "1.9.12",
2929
"@types/prismjs": "1.26.4",

packages/supabase-auth-helpers-qwik/package.json

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
11
{
22
"name": "supabase-auth-helpers-qwik",
3-
"description": "A collection of framework specific Auth utilities for working with Supabase.",
4-
"version": "0.0.3",
3+
"description": "A collection of Qwik framework specific Auth utilities for working with Supabase.",
4+
"version": "0.0.4",
55
"author": "Qwik Team",
66
"bugs": "https://github.com/QwikDev/qwik/issues",
7-
"dependencies": {
8-
"@supabase/auth-helpers-shared": "^0.6.3"
9-
},
107
"devDependencies": {
118
"@builder.io/qwik": "workspace:^",
129
"@builder.io/qwik-city": "workspace:^",
13-
"@supabase/supabase-js": "2.44.4"
10+
"@supabase/ssr": "0.6.1",
11+
"@supabase/supabase-js": "2.49.4"
1412
},
1513
"exports": {
1614
".": {
@@ -31,7 +29,7 @@
3129
"license": "MIT",
3230
"main": "./lib/index.qwik.mjs",
3331
"peerDependencies": {
34-
"@supabase/supabase-js": "^2.44.4"
32+
"@supabase/supabase-js": "^2.49.4"
3533
},
3634
"publishConfig": {
3735
"access": "public"
@@ -40,7 +38,7 @@
4038
"repository": {
4139
"type": "git",
4240
"url": "https://github.com/QwikDev/qwik.git",
43-
"directory": "packages/qwik-auth"
41+
"directory": "packages/supabase-auth-helpers-qwik"
4442
},
4543
"scripts": {
4644
"build": "vite build --mode lib"
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// Methods
2-
export { createBrowserClient, createServerClient } from './utils/createSupabaseClient';
2+
export { createBrowserClient } from './utils/createBrowserClient';
3+
export { createServerClient } from './utils/createServerClient';
34

45
// Types
56
export type { Session, User, SupabaseClient } from '@supabase/supabase-js';
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import type { SupabaseClient } from '@supabase/supabase-js';
2+
import {
3+
createBrowserClient as browserClient,
4+
type CookieMethodsBrowser,
5+
type CookieOptionsWithName,
6+
} from '@supabase/ssr';
7+
import type {
8+
GenericSchema,
9+
SupabaseClientOptions,
10+
} from '@supabase/supabase-js/dist/module/lib/types';
11+
12+
export function createBrowserClient<
13+
Database = any,
14+
SchemaName extends string & keyof Database = 'public' extends keyof Database
15+
? 'public'
16+
: string & keyof Database,
17+
Schema extends GenericSchema = Database[SchemaName] extends GenericSchema
18+
? Database[SchemaName]
19+
: any,
20+
>(
21+
supabaseUrl: string,
22+
supabaseKey: string,
23+
options?: SupabaseClientOptions<SchemaName> & {
24+
cookies?: CookieMethodsBrowser;
25+
cookieOptions?: CookieOptionsWithName;
26+
cookieEncoding?: 'raw' | 'base64url';
27+
isSingleton?: boolean;
28+
}
29+
): SupabaseClient<Database, SchemaName, Schema> {
30+
if (!supabaseUrl || !supabaseKey) {
31+
throw new Error(
32+
'supabaseUrl and supabaseKey are required to create a Supabase client! Find these under `Settings` > `API` in your Supabase dashboard.'
33+
);
34+
}
35+
36+
return browserClient<Database, SchemaName, Schema>(supabaseUrl, supabaseKey, {
37+
...options,
38+
global: {
39+
...options?.global,
40+
headers: {
41+
...options?.global?.headers,
42+
'X-Client-Info': '[email protected]',
43+
},
44+
},
45+
auth: {
46+
storageKey: options?.cookieOptions?.name,
47+
},
48+
});
49+
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
import type { SupabaseClient } from '@supabase/supabase-js';
2+
import { createServerClient as serverClient } from '@supabase/ssr';
3+
import type { CookieMethodsBrowser, CookieOptionsWithName } from '@supabase/ssr';
4+
import type {
5+
GenericSchema,
6+
SupabaseClientOptions,
7+
} from '@supabase/supabase-js/dist/module/lib/types';
8+
import type { RequestEventBase } from 'packages/qwik-city/lib';
9+
10+
export function createServerClient<
11+
Database = any,
12+
SchemaName extends string & keyof Database = 'public' extends keyof Database
13+
? 'public'
14+
: string & keyof Database,
15+
Schema extends GenericSchema = Database[SchemaName] extends GenericSchema
16+
? Database[SchemaName]
17+
: any,
18+
>(
19+
supabaseUrl: string,
20+
supabaseKey: string,
21+
requestEv: RequestEventBase,
22+
options?: SupabaseClientOptions<SchemaName> & {
23+
cookies?: CookieMethodsBrowser;
24+
cookieOptions?: CookieOptionsWithName;
25+
cookieEncoding?: 'raw' | 'base64url';
26+
isSingleton?: boolean;
27+
}
28+
): SupabaseClient<Database, SchemaName, Schema> {
29+
if (!supabaseUrl || !supabaseKey) {
30+
throw new Error(
31+
'supabaseUrl and supabaseKey are required to create a Supabase client! Find these under `Settings` > `API` in your Supabase dashboard.'
32+
);
33+
}
34+
35+
return serverClient<Database, SchemaName, Schema>(supabaseUrl, supabaseKey, {
36+
...options,
37+
global: {
38+
...options?.global,
39+
headers: {
40+
...options?.global?.headers,
41+
'X-Client-Info': '[email protected]',
42+
},
43+
},
44+
auth: {
45+
storageKey: options?.cookieOptions?.name,
46+
},
47+
cookies: {
48+
getAll: () => {
49+
const cookies = requestEv.cookie.getAll();
50+
return Object.keys(cookies).map((name) => {
51+
return { name, value: cookies[name].value };
52+
});
53+
},
54+
setAll: (cookies) => {
55+
cookies.map((cookie) => {
56+
requestEv.cookie.set(cookie.name, cookie.value, cookie.options);
57+
});
58+
},
59+
},
60+
});
61+
}

packages/supabase-auth-helpers-qwik/src/utils/createSupabaseClient.ts

Lines changed: 0 additions & 157 deletions
This file was deleted.

packages/supabase-auth-helpers-qwik/src/utils/storageAdapter.ts

Lines changed: 0 additions & 37 deletions
This file was deleted.

0 commit comments

Comments
 (0)