fix: skip currentPassword check for federated users on change-password

This commit is contained in:
Jannis Braun
2026-03-23 00:48:02 +01:00
parent a888828941
commit 41caf5f90c
+6 -1
View File
@@ -72,7 +72,11 @@ export async function userRoutes(app: FastifyInstance): Promise<void> {
return reply.code(404).send({ error: 'User not found', statusCode: 404 }); return reply.code(404).send({ error: 'User not found', statusCode: 404 });
} }
// All users must provide current password (federated users have a local password hash) // Federated users (replicas on this instance) don't need currentPassword
// their home instance already verified the password change, and JWT auth
// proves identity. The homeInstance field comes from the DB, not the request.
if (!user.homeInstance) {
// Local users must provide current password
if (!currentPassword || typeof currentPassword !== 'string') { if (!currentPassword || typeof currentPassword !== 'string') {
return reply.code(400).send({ error: 'Current password is required', statusCode: 400 }); return reply.code(400).send({ error: 'Current password is required', statusCode: 400 });
} }
@@ -80,6 +84,7 @@ export async function userRoutes(app: FastifyInstance): Promise<void> {
if (!valid) { if (!valid) {
return reply.code(403).send({ error: 'Incorrect password', statusCode: 403 }); return reply.code(403).send({ error: 'Incorrect password', statusCode: 403 });
} }
}
const newHash = await hashPassword(newPassword); const newHash = await hashPassword(newPassword);
db.update(schema.users).set({ passwordHash: newHash, passwordChangedAt: Date.now() }).where(eq(schema.users.id, request.userId)).run(); db.update(schema.users).set({ passwordHash: newHash, passwordChangedAt: Date.now() }).where(eq(schema.users.id, request.userId)).run();