File size: 970 Bytes
6fc3143
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
"use client";

import { Button } from "@/components/ui/button";
import { supabaseClient } from "@/lib/supabase-client";
import { cn } from "@/lib/utils";

interface LoginButtonProps extends React.ButtonHTMLAttributes<HTMLButtonElement> {
    text?: string;
    variant?: "default" | "outline" | "secondary" | "ghost";
    redirectTo?: string;
}

export function LoginButton({
    text = "Sign In",
    variant = "default",
    className,
    redirectTo = "/",
    ...props
}: LoginButtonProps) {

    const handleLogin = async () => {
        await supabaseClient.auth.signInWithOAuth({
            provider: "google",
            options: {
                redirectTo: `${location.origin}/auth/callback?next=${redirectTo}`,
            },
        });
    };

    return (
        <Button
            variant={variant}
            className={cn(className)}
            onClick={handleLogin}
            {...props}
        >
            {text}
        </Button>
    );
}