diff --git a/src/lib/server/auth-utils.ts b/src/lib/server/auth-utils.ts new file mode 100644 index 0000000..cb6509d --- /dev/null +++ b/src/lib/server/auth-utils.ts @@ -0,0 +1,19 @@ +import db from "$lib/drizzle"; +import { eq } from "drizzle-orm"; +import { password_reset_tokens } from "../../schema"; +import { generateId } from "lucia"; +import { TimeSpan, createDate } from "oslo"; + +export async function createPasswordResetToken(userId: string): Promise { + // optionally invalidate all existing tokens + await db.delete(password_reset_tokens).where(eq(password_reset_tokens.user_id, userId)); + const tokenId = generateId(40); + await db + .insert(password_reset_tokens) + .values({ + id: tokenId, + user_id: userId, + expires_at: createDate(new TimeSpan(2, "h")) + }); + return tokenId; +} \ No newline at end of file diff --git a/src/lib/validations/account.ts b/src/lib/validations/account.ts index 27715af..39168d4 100644 --- a/src/lib/validations/account.ts +++ b/src/lib/validations/account.ts @@ -21,6 +21,8 @@ export const changeUserPasswordSchema = z refinePasswords(confirm_password, password, ctx); }); +export type ChangeUserPasswordSchema = typeof changeUserPasswordSchema; + export const updateUserPasswordSchema = userSchema .pick({ password: true, confirm_password: true }) .superRefine(({ confirm_password, password }, ctx) => { diff --git a/src/routes/(app)/(protected)/password/change/+page.svelte b/src/routes/(app)/(protected)/password/change/+page.svelte index c55acbe..a6f1a45 100644 --- a/src/routes/(app)/(protected)/password/change/+page.svelte +++ b/src/routes/(app)/(protected)/password/change/+page.svelte @@ -1,34 +1,25 @@
-

Change Password


@@ -38,39 +29,28 @@ Changing your password will log you out of all devices. - {#if $message} - - {/if} -
- - - {#if $errors.current_password} - {$errors.current_password} - {/if} -
-
- - - {#if $errors.password} - {$errors.password} - {/if} -
-
- - - {#if $errors.confirm_password} - {$errors.confirm_password} - {/if} -
- -
- -
+ + + Current Password + + + + + + + New Password + + + + + + + Confirm New Password + + + + + Submit