2025-11-27 09:09:43 +01:00

60 lines
1.5 KiB
TypeScript

// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
import { AUTH_COOKIE_NAME, BE_BASE_URL } from "@/app/services/constants";
import { NextResponse, type NextRequest } from "next/server";
import { cookies } from "next/headers";
export async function PUT(
request: NextRequest,
context: { params: Promise<{ id: string }> }
) {
try {
const { id } = await context.params;
if (!id) {
return NextResponse.json(
{ success: false, message: "User ID is required" },
{ status: 400 }
);
}
const cookieStore = await cookies();
const token = cookieStore.get(AUTH_COOKIE_NAME)?.value;
if (!token) {
return NextResponse.json(
{ success: false, message: "No authentication token found" },
{ status: 401 }
);
}
const resp = await fetch(
`${BE_BASE_URL}/api/v1/auth/reset-password/${encodeURIComponent(id)}`,
{
method: "PUT",
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${token}`,
},
}
);
let data;
try {
data = await resp.json();
} catch {
data = { success: resp.ok };
}
return NextResponse.json(data, {
status: resp.status,
});
} catch (error: unknown) {
const message = error instanceof Error ? error.message : "Unknown error";
return NextResponse.json(
{ success: false, message: "Internal server error", error: message },
{ status: 500 }
);
}
}