-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclient.ts
More file actions
35 lines (29 loc) · 1.04 KB
/
client.ts
File metadata and controls
35 lines (29 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
"use client";
import { createBrowserClient } from "@supabase/ssr";
export function createSupabaseClient() {
return createBrowserClient(
process.env.NODE_ENV === "production"
? process.env.NEXT_PUBLIC_SUPABASE_URL!
: process.env.NEXT_PUBLIC_DEV_SUPABASE_URL!,
process.env.NODE_ENV === "production"
? process.env.NEXT_PUBLIC_SUPABASE_PUBLISHABLE_KEY!
: process.env.NEXT_PUBLIC_SUPABASE_DEV_PUBLISHABLE_KEY!
);
}
/**
* Get the current auth token from Supabase session (client-side)
* @returns Promise<string> The access token
* @throws Error if token is missing
*/
export async function getAuthToken(): Promise<string> {
const supabase = createSupabaseClient();
("@ts-expect-error");
const { data, error } = await supabase.auth.getSession();
if (error) {
throw new Error(`Failed to get session: ${error.message}`);
}
if (!data.session?.access_token) {
throw new Error("Authorization token is missing.");
}
return data.session.access_token;
}