Files
supabase/examples/auth/nextjs/components/AuthButton.tsx
Thor 雷神 Schaeff 5903b5d4a8 chore: prepare examples for cli bootstrap (#22428)
* chore: prep expo example.

* Modify Flutter user management example to use .env and initialize supabase

* chore: add .env support to swift-user-management

* chore: update supabase dependency for swift-user-management example

* chore: minor expo updates.

* chore: update auth nextjs example.

---------

Co-authored-by: dshukertjr <dshukertjr@gmail.com>
Co-authored-by: Guilherme Souza <grsouza@pm.me>
2024-04-05 17:26:36 +08:00

38 lines
910 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">
Hey, {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>
);
}