Skip to content

Commit

Permalink
feat(db): add server-side supabase client with cookies
Browse files Browse the repository at this point in the history
  • Loading branch information
rikhall1515 committed Apr 18, 2024
1 parent 2e19938 commit d2b7d0a
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions db/server.ts
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.
}
},
},
}
);
};

0 comments on commit d2b7d0a

Please sign in to comment.