feat: change the password in settings
Accounts that only sign in with SSO have no password and do not see it.
This commit is contained in:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user