diff --git a/apps/next/app/auth/confirm/route.ts b/apps/next/app/auth/confirm/route.ts index a9d87c1..cd00059 100644 --- a/apps/next/app/auth/confirm/route.ts +++ b/apps/next/app/auth/confirm/route.ts @@ -2,26 +2,44 @@ import { type EmailOtpType } from "@supabase/supabase-js"; import { cookies } from "next/headers"; import { type NextRequest, NextResponse } from "next/server"; -import { useSupabaseServer } from "@/modules/utils/server"; +import { CookieOptions, createServerClient } from "@supabase/ssr"; 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") ?? "/login"; + 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 cookieStore = cookies(); + const supabase = createServerClient( + process.env.NEXT_PUBLIC_SUPABASE_URL!, + process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY!, + { + cookies: { + get(name: string) { + return cookieStore.get(name)?.value; + }, + set(name: string, value: string, options: CookieOptions) { + cookieStore.set({ name, value, ...options }); + }, + remove(name: string, options: CookieOptions) { + cookieStore.delete({ name, ...options }); + }, + }, + } + ); + const { error } = await supabase.auth.verifyOtp({ type, token_hash, }); + if (!error) { redirectTo.searchParams.delete("next"); return NextResponse.redirect(redirectTo); diff --git a/docs/modules/user.md b/docs/modules/user.md index 383fb7c..ce190d6 100644 --- a/docs/modules/user.md +++ b/docs/modules/user.md @@ -40,6 +40,12 @@ Then copy, paste and execute the contents of file `modules/user/migration.sql` i <<< ../../apps/next/components/user/login-form.tsx#useSignInWithEmailPassword ::: +### `useResetPasswordForEmail` + +::: code-group +<<< ../../apps/next/components/user/reset-password-form.tsx#useResetPasswordForEmail +::: + ### `useSignOut` ::: code-group