Skip to content

Commit

Permalink
Updating routes
Browse files Browse the repository at this point in the history
  • Loading branch information
iamhectorsosa committed Mar 14, 2024
1 parent 14c0576 commit 0986634
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 4 deletions.
26 changes: 22 additions & 4 deletions apps/next/app/auth/confirm/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
6 changes: 6 additions & 0 deletions docs/modules/user.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 0986634

Please sign in to comment.