|
1 | | -import { redirect } from "next/navigation"; |
2 | | -import { createClient } from "@/lib/supabase/server"; |
| 1 | +"use client"; |
| 2 | + |
3 | 3 | import { |
4 | 4 | Card, |
5 | 5 | CardContent, |
6 | 6 | CardDescription, |
7 | 7 | CardHeader, |
8 | 8 | CardTitle, |
9 | 9 | } from "@/components/ui/card"; |
10 | | -import { Input } from "@/components/ui/input"; |
11 | | -import { Label } from "@/components/ui/label"; |
12 | 10 | import { Button } from "@/components/ui/button"; |
| 11 | +import { createClient } from "@/lib/supabase/client"; |
| 12 | +import { useSearchParams } from "next/navigation"; |
| 13 | +import { Suspense } from "react"; |
13 | 14 |
|
14 | | -export default async function LoginPage(props: { |
15 | | - searchParams: Promise<{ error?: string }>; |
16 | | -}) { |
17 | | - const { error } = await props.searchParams; |
18 | | - |
19 | | - async function signIn(formData: FormData) { |
20 | | - "use server"; |
| 15 | +function GoogleIcon() { |
| 16 | + return ( |
| 17 | + <svg className="h-5 w-5" viewBox="0 0 24 24"> |
| 18 | + <path |
| 19 | + d="M22.56 12.25c0-.78-.07-1.53-.2-2.25H12v4.26h5.92a5.06 5.06 0 0 1-2.2 3.32v2.77h3.57c2.08-1.92 3.28-4.74 3.28-8.1z" |
| 20 | + fill="#4285F4" |
| 21 | + /> |
| 22 | + <path |
| 23 | + d="M12 23c2.97 0 5.46-.98 7.28-2.66l-3.57-2.77c-.98.66-2.23 1.06-3.71 1.06-2.86 0-5.29-1.93-6.16-4.53H2.18v2.84C3.99 20.53 7.7 23 12 23z" |
| 24 | + fill="#34A853" |
| 25 | + /> |
| 26 | + <path |
| 27 | + d="M5.84 14.09c-.22-.66-.35-1.36-.35-2.09s.13-1.43.35-2.09V7.07H2.18C1.43 8.55 1 10.22 1 12s.43 3.45 1.18 4.93l2.85-2.22.81-.62z" |
| 28 | + fill="#FBBC05" |
| 29 | + /> |
| 30 | + <path |
| 31 | + d="M12 5.38c1.62 0 3.06.56 4.21 1.64l3.15-3.15C17.45 2.09 14.97 1 12 1 7.7 1 3.99 3.47 2.18 7.07l3.66 2.84c.87-2.6 3.3-4.53 6.16-4.53z" |
| 32 | + fill="#EA4335" |
| 33 | + /> |
| 34 | + </svg> |
| 35 | + ); |
| 36 | +} |
21 | 37 |
|
22 | | - const email = formData.get("email") as string; |
23 | | - const password = formData.get("password") as string; |
| 38 | +function LoginForm() { |
| 39 | + const searchParams = useSearchParams(); |
| 40 | + const error = searchParams.get("error"); |
24 | 41 |
|
25 | | - const supabase = await createClient(); |
26 | | - const { error } = await supabase.auth.signInWithPassword({ |
27 | | - email, |
28 | | - password, |
| 42 | + const handleGoogleSignIn = async () => { |
| 43 | + const supabase = createClient(); |
| 44 | + await supabase.auth.signInWithOAuth({ |
| 45 | + provider: "google", |
| 46 | + options: { |
| 47 | + redirectTo: `${window.location.origin}/dashboard/auth/callback`, |
| 48 | + }, |
29 | 49 | }); |
30 | | - |
31 | | - if (error) { |
32 | | - redirect(`/dashboard/login?error=${encodeURIComponent(error.message)}`); |
33 | | - } |
34 | | - |
35 | | - redirect("/dashboard"); |
36 | | - } |
| 50 | + }; |
37 | 51 |
|
38 | 52 | return ( |
39 | 53 | <div className="flex min-h-screen items-center justify-center bg-background"> |
40 | 54 | <Card className="w-full max-w-sm"> |
41 | | - <CardHeader> |
| 55 | + <CardHeader className="text-center"> |
42 | 56 | <CardTitle className="text-2xl">CodingCat.dev</CardTitle> |
43 | 57 | <CardDescription> |
44 | 58 | Sign in to the Content Ops Dashboard |
45 | 59 | </CardDescription> |
46 | 60 | </CardHeader> |
47 | 61 | <CardContent> |
48 | | - <form action={signIn} className="flex flex-col gap-4"> |
| 62 | + <div className="flex flex-col gap-4"> |
49 | 63 | {error && ( |
50 | 64 | <div className="rounded-md bg-destructive/10 p-3 text-sm text-destructive"> |
51 | 65 | {error} |
52 | 66 | </div> |
53 | 67 | )} |
54 | | - <div className="flex flex-col gap-2"> |
55 | | - <Label htmlFor="email">Email</Label> |
56 | | - <Input |
57 | | - id="email" |
58 | | - name="email" |
59 | | - type="email" |
60 | | - placeholder="admin@codingcat.dev" |
61 | | - required |
62 | | - /> |
63 | | - </div> |
64 | | - <div className="flex flex-col gap-2"> |
65 | | - <Label htmlFor="password">Password</Label> |
66 | | - <Input |
67 | | - id="password" |
68 | | - name="password" |
69 | | - type="password" |
70 | | - required |
71 | | - /> |
72 | | - </div> |
73 | | - <Button type="submit" className="w-full"> |
74 | | - Sign In |
| 68 | + <Button |
| 69 | + variant="outline" |
| 70 | + className="w-full gap-2" |
| 71 | + onClick={handleGoogleSignIn} |
| 72 | + > |
| 73 | + <GoogleIcon /> |
| 74 | + Sign in with Google |
75 | 75 | </Button> |
76 | | - </form> |
| 76 | + <p className="text-center text-xs text-muted-foreground"> |
| 77 | + Access restricted to authorized accounts only. |
| 78 | + </p> |
| 79 | + </div> |
77 | 80 | </CardContent> |
78 | 81 | </Card> |
79 | 82 | </div> |
80 | 83 | ); |
81 | 84 | } |
| 85 | + |
| 86 | +export default function LoginPage() { |
| 87 | + return ( |
| 88 | + <Suspense> |
| 89 | + <LoginForm /> |
| 90 | + </Suspense> |
| 91 | + ); |
| 92 | +} |
0 commit comments