Spaces:
Sleeping
Sleeping
Download src/lib/serverSupabase.ts from ihatebaselines/purcar-chat-api: direct link, hf CLI and curl.
- Browser
- Download file 857 Bytes
-
https://huggingface.co/spaces/ihatebaselines/purcar-chat-api/resolve/main/src/lib/serverSupabase.ts
- Command line
-
hf download hf://spaces/ihatebaselines/purcar-chat-api/src/lib/serverSupabase.ts
-
curl -L -o serverSupabase.ts https://huggingface.co/spaces/ihatebaselines/purcar-chat-api/resolve/main/src/lib/serverSupabase.ts
857 Bytes
| import { createClient } from "@supabase/supabase-js"; | |
| const url = process.env.NEXT_PUBLIC_SUPABASE_URL; | |
| const anonKey = process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY; | |
| export function getBearerToken(request: Request): string | null { | |
| const value = request.headers.get("authorization") || ""; | |
| return value.toLowerCase().startsWith("bearer ") ? value.slice(7).trim() : null; | |
| } | |
| export async function createAuthenticatedClient(request: Request) { | |
| const token = getBearerToken(request); | |
| if (!url || !anonKey || !token) return null; | |
| const client = createClient(url, anonKey, { | |
| auth: { persistSession: false, autoRefreshToken: false }, | |
| global: { headers: { Authorization: `Bearer ${token}` } }, | |
| }); | |
| const { data, error } = await client.auth.getUser(token); | |
| if (error || !data.user) return null; | |
| return { client, user: data.user, token }; | |
| } | |