Files
neta/app/invite/[token]/actions.ts
T

28 lines
859 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.
"use server";
import { redirect } from "next/navigation";
import {
acceptPortalInvitation,
PortalInvitationError,
} from "@/server/auth/invitations";
export async function acceptInvitation(formData: FormData) {
const token = String(formData.get("token") ?? "");
const displayName = String(formData.get("displayName") ?? "");
const password = String(formData.get("password") ?? "");
try {
await acceptPortalInvitation({ token, displayName, password });
} catch (error) {
const message =
error instanceof PortalInvitationError
? error.message
: "Portal hesabı oluşturulamadı.";
redirect(`/invite/${encodeURIComponent(token)}?error=true&message=${encodeURIComponent(message)}`);
}
redirect(
`/login?message=${encodeURIComponent("Portal hesabın oluşturuldu. Şimdi giriş yapabilirsin.")}`,
);
}