Skip to content

Commit

Permalink
feat(db): add auth callback with redirect
Browse files Browse the repository at this point in the history
  • Loading branch information
rikhall1515 committed Apr 18, 2024
1 parent c84ad94 commit fca54d4
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions app/auth/callback/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { NextResponse } from "next/server";

import { createClient } from "@/db/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`);
}

0 comments on commit fca54d4

Please sign in to comment.