From 091bcd2e88c8120089c7cf4f71fa7c92990bd26f Mon Sep 17 00:00:00 2001 From: Bradley Shellnut Date: Sun, 14 Jul 2024 20:59:51 -0700 Subject: [PATCH 1/2] Refactor to use recovery code on TOTP as separate form. --- src/lib/validations/auth.ts | 6 +- src/routes/(auth)/login/+page.server.ts | 4 +- src/routes/(auth)/login/+page.svelte | 39 +++++---- src/routes/(auth)/totp/+page.server.ts | 35 ++++----- src/routes/(auth)/totp/+page.svelte | 100 ++++++++++++++---------- 5 files changed, 104 insertions(+), 80 deletions(-) diff --git a/src/lib/validations/auth.ts b/src/lib/validations/auth.ts index d5af946..ba17051 100644 --- a/src/lib/validations/auth.ts +++ b/src/lib/validations/auth.ts @@ -25,5 +25,9 @@ export const signInSchema = z.object({ }); export const totpSchema = z.object({ - totpToken: z.string().trim().min(6).max(10), + totpToken: z.string().trim().min(6).max(6), +}); + +export const recoveryCodeSchema = z.object({ + recoveryCode: z.string().trim().min(10).max(10), }); diff --git a/src/routes/(auth)/login/+page.server.ts b/src/routes/(auth)/login/+page.server.ts index 1bf98a6..6d91a2a 100644 --- a/src/routes/(auth)/login/+page.server.ts +++ b/src/routes/(auth)/login/+page.server.ts @@ -1,5 +1,5 @@ import { fail, error, type Actions } from '@sveltejs/kit'; -import { eq } from 'drizzle-orm'; +import { eq, or } from 'drizzle-orm'; import { Argon2id } from 'oslo/password'; import { zod } from 'sveltekit-superforms/adapters'; import { setError, superValidate } from 'sveltekit-superforms/server'; @@ -58,7 +58,7 @@ export const actions: Actions = { let session; let sessionCookie; const user: Users | undefined = await db.query.users.findFirst({ - where: eq(users.username, form.data.username), + where: or(eq(users.username, form.data.username), eq(users.email, form.data.username)), }); if (!user) { diff --git a/src/routes/(auth)/login/+page.svelte b/src/routes/(auth)/login/+page.svelte index a0a9232..92c6f36 100644 --- a/src/routes/(auth)/login/+page.svelte +++ b/src/routes/(auth)/login/+page.svelte @@ -41,15 +41,29 @@
-
-

- Log into your account -

+ > + Log into your account + + {@render usernamePasswordForm()} +

+ By clicking continue, you agree to our + + Terms of Use + + and + + Privacy Policy + . +

+
+ +{#snippet usernamePasswordForm()} + - Username + Username/Email @@ -62,22 +76,13 @@ Login -

- By clicking continue, you agree to our - - Terms of Use - - and - - Privacy Policy - . -

- +{/snippet}