Files
zitadel/apps/login/src/app/api/resetpassword/route.ts
peintnermax 775ead416c fix build
2024-08-21 14:34:45 +02:00

32 lines
895 B
TypeScript

import { listUsers, passwordReset } from "@/lib/zitadel";
import { NextRequest, NextResponse } from "next/server";
export async function POST(request: NextRequest) {
const body = await request.json();
if (body) {
const { loginName, organization } = body;
return listUsers({
userName: loginName,
organizationId: organization,
}).then((users) => {
if (
users.details &&
Number(users.details.totalResult) == 1 &&
users.result[0].userId
) {
const userId = users.result[0].userId;
return passwordReset(userId)
.then((resp) => {
return NextResponse.json(resp);
})
.catch((error) => {
return NextResponse.json(error, { status: 500 });
});
} else {
return NextResponse.json({ error: "User not found" }, { status: 404 });
}
});
}
}