Skip to content

Commit a12a15a

Browse files
Miriaddashboard
andcommitted
feat: switch dashboard login to Google OAuth only
Replace email/password form with Google sign-in button. Uses Supabase OAuth with redirect to /dashboard/auth/callback. Login page is now a client component for the OAuth flow. Co-authored-by: dashboard <dashboard@miriad.systems>
1 parent d7cbe79 commit a12a15a

File tree

1 file changed

+59
-48
lines changed

1 file changed

+59
-48
lines changed
Lines changed: 59 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,81 +1,92 @@
1-
import { redirect } from "next/navigation";
2-
import { createClient } from "@/lib/supabase/server";
1+
"use client";
2+
33
import {
44
Card,
55
CardContent,
66
CardDescription,
77
CardHeader,
88
CardTitle,
99
} from "@/components/ui/card";
10-
import { Input } from "@/components/ui/input";
11-
import { Label } from "@/components/ui/label";
1210
import { Button } from "@/components/ui/button";
11+
import { createClient } from "@/lib/supabase/client";
12+
import { useSearchParams } from "next/navigation";
13+
import { Suspense } from "react";
1314

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+
}
2137

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");
2441

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+
},
2949
});
30-
31-
if (error) {
32-
redirect(`/dashboard/login?error=${encodeURIComponent(error.message)}`);
33-
}
34-
35-
redirect("/dashboard");
36-
}
50+
};
3751

3852
return (
3953
<div className="flex min-h-screen items-center justify-center bg-background">
4054
<Card className="w-full max-w-sm">
41-
<CardHeader>
55+
<CardHeader className="text-center">
4256
<CardTitle className="text-2xl">CodingCat.dev</CardTitle>
4357
<CardDescription>
4458
Sign in to the Content Ops Dashboard
4559
</CardDescription>
4660
</CardHeader>
4761
<CardContent>
48-
<form action={signIn} className="flex flex-col gap-4">
62+
<div className="flex flex-col gap-4">
4963
{error && (
5064
<div className="rounded-md bg-destructive/10 p-3 text-sm text-destructive">
5165
{error}
5266
</div>
5367
)}
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
7575
</Button>
76-
</form>
76+
<p className="text-center text-xs text-muted-foreground">
77+
Access restricted to authorized accounts only.
78+
</p>
79+
</div>
7780
</CardContent>
7881
</Card>
7982
</div>
8083
);
8184
}
85+
86+
export default function LoginPage() {
87+
return (
88+
<Suspense>
89+
<LoginForm />
90+
</Suspense>
91+
);
92+
}

0 commit comments

Comments
 (0)