-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
60c2e51
commit 978cd3d
Showing
1 changed file
with
33 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { type EmailOtpType } from "@supabase/supabase-js"; | ||
import { cookies } from "next/headers"; | ||
import { type NextRequest, NextResponse } from "next/server"; | ||
|
||
import { useSupabaseServer } from "@/modules/utils/supabase-server"; | ||
|
||
export async function GET(request: NextRequest) { | ||
const { searchParams } = new URL(request.url); | ||
const token_hash = searchParams.get("token_hash"); | ||
const type = searchParams.get("type") as EmailOtpType | null; | ||
const next = searchParams.get("next") ?? "/"; | ||
|
||
const redirectTo = request.nextUrl.clone(); | ||
redirectTo.pathname = next; | ||
redirectTo.searchParams.delete("token_hash"); | ||
redirectTo.searchParams.delete("type"); | ||
|
||
const supabase = useSupabaseServer({ cookies }); | ||
|
||
if (token_hash && type) { | ||
const { error } = await supabase.auth.verifyOtp({ | ||
type, | ||
token_hash, | ||
}); | ||
if (!error) { | ||
redirectTo.searchParams.delete("next"); | ||
return NextResponse.redirect(redirectTo); | ||
} | ||
} | ||
|
||
redirectTo.pathname = "/"; //TODO | ||
return NextResponse.redirect(redirectTo); | ||
} |