-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(db): add server-side supabase client with cookies
- Loading branch information
1 parent
2e19938
commit d2b7d0a
Showing
1 changed file
with
36 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { createServerClient, type CookieOptions } from "@supabase/ssr"; | ||
import { cookies } from "next/headers"; | ||
|
||
export const createClient = () => { | ||
const cookieStore = cookies(); | ||
|
||
return createServerClient( | ||
process.env.NEXT_PUBLIC_SUPABASE_URL!, | ||
process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY!, | ||
{ | ||
cookies: { | ||
get(name: string) { | ||
return cookieStore.get(name)?.value; | ||
}, | ||
set(name: string, value: string, options: CookieOptions) { | ||
try { | ||
cookieStore.set({ name, value, ...options }); | ||
} catch (error) { | ||
// The `set` method was called from a Server Component. | ||
// This can be ignored if you have middleware refreshing | ||
// user sessions. | ||
} | ||
}, | ||
remove(name: string, options: CookieOptions) { | ||
try { | ||
cookieStore.set({ name, value: "", ...options }); | ||
} catch (error) { | ||
// The `delete` method was called from a Server Component. | ||
// This can be ignored if you have middleware refreshing | ||
// user sessions. | ||
} | ||
}, | ||
}, | ||
} | ||
); | ||
}; |