From c3225a7b91b68c95874f0eb3d19872e243d570f0 Mon Sep 17 00:00:00 2001 From: Niklas Haiden Date: Sat, 21 Nov 2026 19:16:22 +0100 Subject: [PATCH] feat: change the password in settings Accounts that only sign in with SSO have no password and do not see it. --- src/lib/dashboard.functions.ts | 22 +++++++++++-- src/routes/settings.tsx | 59 ++++++++++++++++++++++++++++++++++ 2 files changed, 78 insertions(+), 3 deletions(-) diff --git a/src/lib/dashboard.functions.ts b/src/lib/dashboard.functions.ts index ccb6910..49d4d70 100644 --- a/src/lib/dashboard.functions.ts +++ b/src/lib/dashboard.functions.ts @@ -3,7 +3,14 @@ import { getRequestHeaders } from "@tanstack/react-start/server" import { and, asc, eq, inArray, sql } from "drizzle-orm" import { z } from "zod" import { db } from "@/db" -import { card, dashboard, link, settings, wallpaper } from "@/db/schema" +import { + account, + card, + dashboard, + link, + settings, + wallpaper, +} from "@/db/schema" import { auth, requireUser, signUpEnabled, ssoName } from "@/lib/auth" import { CLOCK_FONTS, CLOCK_STYLES } from "@/lib/clock" import { ENGINES, parseSuggestions } from "@/lib/search" @@ -57,13 +64,18 @@ export const getDashboard = createServerFn({ method: "GET" }) const session = await auth.api.getSession({ headers: getRequestHeaders() }) if (!session) return null const userId = session.user.id - const [dashboards, rows] = await Promise.all([ + const [dashboards, rows, passwords] = await Promise.all([ db .select(shown) .from(dashboard) .where(eq(dashboard.userId, userId)) .orderBy(asc(dashboard.createdAt)), db.select().from(settings).where(eq(settings.userId, userId)), + // someone who only ever signed in with SSO has no password to change + db.$count( + account, + and(eq(account.userId, userId), eq(account.providerId, "credential")) + ), ]) // Cards need a dashboard and links need a card, so nobody is left without one. // shortcut: two first loads at the same moment make two of each, add a unique @@ -108,7 +120,11 @@ export const getDashboard = createServerFn({ method: "GET" }) .returning({ id: card.id, name: card.name })) ) return { - user: { name: session.user.name, email: session.user.email }, + user: { + name: session.user.name, + email: session.user.email, + hasPassword: passwords > 0, + }, dashboards, dashboardId, defaultDashboardId: byDefault.id, diff --git a/src/routes/settings.tsx b/src/routes/settings.tsx index ffbddf5..ffdaeab 100644 --- a/src/routes/settings.tsx +++ b/src/routes/settings.tsx @@ -640,6 +640,65 @@ function Settings() { + {data.user.hasPassword && ( + + +
Password
+ + A new password signs you out on your other devices. + +
+ +
{ + e.preventDefault() + const form = e.currentTarget + const fields = new FormData(form) + void run(async () => { + // Better Auth returns { error } instead of throwing + const { error: failure } = + await authClient.changePassword({ + currentPassword: String(fields.get("current")), + newPassword: String(fields.get("new")), + revokeOtherSessions: true, + }) + if (failure) + return ( + failure.message || + "Could not change the password." + ) + form.reset() + }) + }} + > + + Current password + + + + New password + + + +
+
+
+ )}