Add callback and error auth route + rename login to auth path

This commit is contained in:
sirin 2024-08-30 21:00:18 +07:00
parent e14ab28185
commit 12e87c5339
3 changed files with 32 additions and 8 deletions

View File

@ -0,0 +1,24 @@
import { createSupabaseClient } from "@/lib/supabase/serverComponentClient";
import { NextResponse } from "next/server";
export async function GET(request: Request) {
const { searchParams, origin } = new URL(request.url);
const code = searchParams.get("code");
// if "next" is in param, use it in the redirect URL
const next = searchParams.get("next") ?? "/";
if (code) {
const supabase = createSupabaseClient();
const { error } = await supabase.auth.exchangeCodeForSession(code);
if (!error) {
return NextResponse.redirect(`${origin}${next}`);
}
}
// return the user to an error page with instructions
return NextResponse.redirect(`${origin}/auth/error`);
}

View File

@ -0,0 +1,3 @@
export default function AuthError() {
return <div>Authentication Error</div>;
}

View File

@ -2,6 +2,9 @@ import Image from "next/image";
import { Button } from "@/components/ui/button"; import { Button } from "@/components/ui/button";
import { Card, CardContent, CardFooter, CardDescription, CardHeader, CardTitle } from "@/components/ui/card"; import { Card, CardContent, CardFooter, CardDescription, CardHeader, CardTitle } from "@/components/ui/card";
import { LoginButton } from "@/components/auth/loginButton";
import { LogoutButton } from "@/components/auth/logoutButton";
export default function Login() { export default function Login() {
return ( return (
<div <div
@ -16,14 +19,8 @@ export default function Login() {
</CardHeader> </CardHeader>
<CardContent className="flex flex-col gap-y-2 mx-28"> <CardContent className="flex flex-col gap-y-2 mx-28">
<p className="self-center font-semibold text-slate-800">Continue With</p> <p className="self-center font-semibold text-slate-800">Continue With</p>
<Button className="bg-foreground gap-2 rounded-xl"> <LoginButton />
<Image src={"/logo/google.svg"} width={30} height={30} alt={"Google"} /> <LogoutButton />
Continue with Google
</Button>
<Button className="gap-2 rounded-xl">
<Image src={"/logo/facebook.svg"} width={30} height={30} alt={"Google"} />
Continue with Facebook
</Button>
</CardContent> </CardContent>
<CardFooter className="text-xs justify-center"> <CardFooter className="text-xs justify-center">
By signing up, you agree to the Terms of Service and acknowledge youve read our Privacy Policy. By signing up, you agree to the Terms of Service and acknowledge youve read our Privacy Policy.