15 lines
668 B
TypeScript
15 lines
668 B
TypeScript
import { assertSameOrigin, authFailure, changeAccountPassword, jsonResponse, readJsonObject, requireApiUser, sessionCookie } from '@/lib/server/auth';
|
|
|
|
export const runtime = 'nodejs';
|
|
export const dynamic = 'force-dynamic';
|
|
|
|
export async function POST(request: Request) {
|
|
try {
|
|
assertSameOrigin(request);
|
|
const current = await requireApiUser({ allowPasswordChange: true });
|
|
const body = await readJsonObject(request);
|
|
const { user, token } = await changeAccountPassword(current.userId, body.currentPassword, body.newPassword);
|
|
return jsonResponse({ user }, 200, sessionCookie(token, request));
|
|
} catch (error) { return authFailure(error); }
|
|
}
|