SPB Git

spb/autoscholar

Public
929 B · 20 lines typescript
1import { SESSION_COOKIE } from "@autoscholar/auth";2import { changePassword } from "@autoscholar/core";3import { ChangePasswordRequest } from "@autoscholar/schemas";4import { cookies } from "next/headers";5import { handler, json, parseBody } from "@/lib/server/api";6import { db } from "@/lib/server/db";7import { cookieOptions, requireAdmin, sessionToken } from "@/lib/server/session";89export const runtime = "nodejs";1011export const POST = handler(async (req) => {12  const sess = await requireAdmin(req, { mutation: true, allowPendingRotation: true });13  const body = await parseBody(req, ChangePasswordRequest, 8 * 1024);14  const token = (await sessionToken())!;15  const rotated = await changePassword(db(), token, body.currentPassword, body.newPassword, { ip: sess.ip });16  const jar = await cookies();17  jar.set(SESSION_COOKIE, rotated.token, cookieOptions());18  return json({ ok: true, csrfToken: rotated.csrfToken });19});20
Files · main
Menu

Theme