forked from codechefPesuecc/CodeChef-PESUECC-Chapter
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathroute.ts
More file actions
28 lines (24 loc) · 802 Bytes
/
Copy pathroute.ts
File metadata and controls
28 lines (24 loc) · 802 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import { NextResponse } from "next/server";
import { resetPassword } from "@/server/auth/reset";
export const dynamic = "force-dynamic";
export async function POST(req: Request) {
let body: { token?: string; password?: string };
try {
body = await req.json();
} catch {
return NextResponse.json({ ok: false, error: "Invalid JSON." }, { status: 400 });
}
const token = String(body.token ?? "");
const password = String(body.password ?? "");
if (!token) {
return NextResponse.json(
{ ok: false, error: "Missing reset token." },
{ status: 400 },
);
}
const result = await resetPassword(token, password);
if (!result.ok) {
return NextResponse.json({ ok: false, error: result.error }, { status: 400 });
}
return NextResponse.json({ ok: true });
}