Delete old files and create new nextjs+supabase project

This commit is contained in:
2024-01-14 17:13:02 +01:00
parent 7a611cbcc4
commit f1dac2559e
34 changed files with 1697 additions and 2674 deletions

40
components/AuthButton.tsx Normal file
View File

@@ -0,0 +1,40 @@
import { createClient } from "@/utils/supabase/server";
import Link from "next/link";
import { cookies } from "next/headers";
import { redirect } from "next/navigation";
export default async function AuthButton() {
const cookieStore = cookies();
const supabase = createClient(cookieStore);
const {
data: { user },
} = await supabase.auth.getUser();
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}!
<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>
);
}