Add login-logout button component

This commit is contained in:
sirin 2024-08-30 20:59:12 +07:00
parent d050932cb6
commit e14ab28185
2 changed files with 41 additions and 0 deletions

View File

@ -0,0 +1,25 @@
"use client";
import Image from "next/image";
import { createSupabaseClient } from "@/lib/supabase/clientComponentClient";
import { Button } from "@/components/ui/button";
export function LoginButton(props: { nextUrl?: string }) {
const supabase = createSupabaseClient();
const handleLogin = async () => {
await supabase.auth.signInWithOAuth({
provider: "google",
options: {
redirectTo: `${location.origin}/auth/callback?next=${props.nextUrl || ""}`,
},
});
};
return (
<Button className="bg-foreground gap-2 rounded-xl" onClick={handleLogin}>
<Image src={"/logo/google.svg"} width={30} height={30} alt={"Google"} />
Continue with Google
</Button>
);
}

View File

@ -0,0 +1,16 @@
"use client";
import { createSupabaseClient } from "@/lib/supabase/clientComponentClient";
import { useRouter } from "next/navigation";
export function LogoutButton() {
const supabase = createSupabaseClient();
const router = useRouter();
const handleLogout = async () => {
await supabase.auth.signOut();
router.push("/");
};
return <button onClick={handleLogout}>Logout</button>;
}