feat(auth): add user profile page and display name update

Add PATCH /api/auth/me endpoint to update user display name
Create UserProfileView for managing account details and email status
Update AppShell sidebar to link authenticated user to profile page
This commit is contained in:
2026-05-02 22:38:33 +08:00
parent 4a42756e2e
commit 36e10a06b0
10 changed files with 387 additions and 8 deletions

View File

@@ -507,6 +507,29 @@ export async function getUserBySessionToken(token: string): Promise<AuthUser | n
return user ? toPublicUser(user) : null;
}
export async function updateCurrentUser(
userId: number,
payload: Record<string, unknown>,
locale = defaultLocale
): Promise<AuthUser> {
const displayName = await cleanDisplayName(payload.displayName, locale);
const user = await queryOne<UserRow>(
`
UPDATE users
SET display_name = $1, updated_at = now()
WHERE id = $2
RETURNING id, email, display_name, email_verified_at
`,
[displayName, userId]
);
if (!user) {
throw statusError(await systemMessage(locale || defaultLocale, 'server.errors.loginRequired'), 401);
}
return toPublicUser(user);
}
export async function logoutSession(token: string): Promise<void> {
if (token.length < 32) {
return;