mirror of
https://github.com/supabase/supabase.git
synced 2026-10-18 07:39:07 +03:00
Add the Realtime Authorization Demo --------- Co-authored-by: Wen Bo Xie <5532241+w3b6x9@users.noreply.github.com> Co-authored-by: Wen Bo Xie <wenbo.xie3@gmail.com>
38 lines
909 B
TypeScript
38 lines
909 B
TypeScript
import { createClient } from "@/utils/supabase/server";
|
|
import Link from "next/link";
|
|
import { redirect } from "next/navigation";
|
|
|
|
export default async function AuthButton() {
|
|
const supabase = createClient();
|
|
|
|
const {
|
|
data: { user },
|
|
} = await supabase.auth.getUser();
|
|
|
|
const signOut = async () => {
|
|
"use server";
|
|
|
|
const supabase = createClient();
|
|
await supabase.auth.signOut();
|
|
return redirect("/login");
|
|
};
|
|
|
|
return user ? (
|
|
<div className="flex items-center gap-4">
|
|
{user.email}{" "}
|
|
<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>
|
|
);
|
|
}
|