Files
neta/app/api/portal-invitations/accept/route.ts
T

30 lines
963 B
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { NextResponse } from "next/server";
import {
acceptPortalInvitation,
PortalInvitationError,
} from "@/server/auth/invitations";
export async function POST(request: Request) {
try {
const body = await request.json();
await acceptPortalInvitation({
token: body.token,
displayName: body.displayName,
password: body.password,
});
return NextResponse.json({ success: true }, { status: 201 });
} catch (error) {
if (error instanceof SyntaxError) {
return NextResponse.json({ error: "Geçersiz JSON gövdesi." }, { status: 400 });
}
if (error instanceof PortalInvitationError) {
const status = error.code === "INVALID_INPUT" ? 400 : 409;
return NextResponse.json({ error: error.message, code: error.code }, { status });
}
console.error("Portal invitation accept failed", error);
return NextResponse.json({ error: "Portal hesabı oluşturulamadı." }, { status: 500 });
}
}