chore: other code

This commit is contained in:
liuweiqing 2024-02-07 16:13:20 +08:00
parent 1d4fbaf8e4
commit a3d1cebd09
2 changed files with 19 additions and 8 deletions

View File

@ -1,18 +1,19 @@
import { createServerClient, type CookieOptions } from '@supabase/ssr'
import { cookies } from 'next/headers'
import { createServerClient, type CookieOptions } from "@supabase/ssr";
import { cookies } from "next/headers";
export const createClient = (cookieStore: ReturnType<typeof cookies>) => {
return createServerClient(
process.env.NEXT_PUBLIC_SUPABASE_URL!,
process.env.SUPABASE_SECRET_KEY ||
process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY!,
{
cookies: {
get(name: string) {
return cookieStore.get(name)?.value
return cookieStore.get(name)?.value;
},
set(name: string, value: string, options: CookieOptions) {
try {
cookieStore.set({ name, value, ...options })
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
@ -21,7 +22,7 @@ export const createClient = (cookieStore: ReturnType<typeof cookies>) => {
},
remove(name: string, options: CookieOptions) {
try {
cookieStore.set({ name, value: '', ...options })
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
@ -30,5 +31,5 @@ export const createClient = (cookieStore: ReturnType<typeof cookies>) => {
},
},
}
)
}
);
};

View File

@ -0,0 +1,10 @@
"use server";
import { cookies } from "next/headers";
import { createClient } from "@/utils/supabase/server";
export const signOut = async () => {
const cookieStore = cookies();
const supabase = createClient(cookieStore);
await supabase.auth.signOut();
};