49 lines
1.3 KiB
TypeScript
49 lines
1.3 KiB
TypeScript
import { createClient } from "@/utils/supabase/server";
|
|
import Link from "next/link";
|
|
import { cookies } from "next/headers";
|
|
import { redirect } from "next/navigation";
|
|
import { insertUserProfile } from "@/utils/supabase/supabaseutils";
|
|
|
|
export default async function AuthButton() {
|
|
const cookieStore = cookies();
|
|
const supabase = createClient(cookieStore);
|
|
|
|
const {
|
|
data,
|
|
data: { user },
|
|
} = await supabase.auth.getUser();
|
|
//profiles表 插入用户信息
|
|
await insertUserProfile(data, supabase);
|
|
// console.log("1111 in AuthButton user:", user);
|
|
const signOut = async () => {
|
|
"use server";
|
|
|
|
const cookieStore = cookies();
|
|
const supabase = createClient(cookieStore);
|
|
await supabase.auth.signOut();
|
|
|
|
return redirect("/login");
|
|
};
|
|
|
|
return user ? (
|
|
<div className="flex items-center gap-4">
|
|
Hey, {user.email}!
|
|
{/* <div className="vip-icon bg-yellow-400 text-white p-2 rounded-full shadow-lg animate-pulse">
|
|
VIP
|
|
</div> */}
|
|
<form action={signOut}>
|
|
<button className="py-2 px-4 rounded-md no-underline bg-btn-background hover:bg-btn-background-hover">
|
|
Logout
|
|
</button>
|
|
</form>
|
|
</div>
|
|
) : (
|
|
<Link
|
|
href="/login"
|
|
className="py-2 px-3 flex rounded-md no-underline bg-btn-background hover:bg-btn-background-hover"
|
|
>
|
|
Login
|
|
</Link>
|
|
);
|
|
}
|