mirror of
https://github.com/hanzoai/next.js.git
synced 2026-09-24 17:00:51 +00:00
### What? [1] Add protected page [2] Add pending state ### Why? [1] People using incorrect ways to protect pages [2] No feedback that the login page is doing anything when buttons clicked ### How? [1] Redirect user to protected page after successful authentication [2] Use useFormStatus to determine whether the form is in a pending state --------- Co-authored-by: Sam Ko <[email protected]>
20 lines
725 B
TypeScript
20 lines
725 B
TypeScript
import { createClient } from "@/utils/supabase/server";
|
|
import { NextResponse } from "next/server";
|
|
|
|
export async function GET(request: Request) {
|
|
// The `/auth/callback` route is required for the server-side auth flow implemented
|
|
// by the SSR package. It exchanges an auth code for the user's session.
|
|
// https://supabase.com/docs/guides/auth/server-side/nextjs
|
|
const requestUrl = new URL(request.url);
|
|
const code = requestUrl.searchParams.get("code");
|
|
const origin = requestUrl.origin;
|
|
|
|
if (code) {
|
|
const supabase = createClient();
|
|
await supabase.auth.exchangeCodeForSession(code);
|
|
}
|
|
|
|
// URL to redirect to after sign up process completes
|
|
return NextResponse.redirect(`${origin}/protected`);
|
|
}
|