Skip to content

Commit

Permalink
Adding signup route
Browse files Browse the repository at this point in the history
  • Loading branch information
iamhectorsosa committed Feb 14, 2024
1 parent 60c2e51 commit 978cd3d
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions playground/app/auth/confirm/route.ts
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);
}

0 comments on commit 978cd3d

Please sign in to comment.