/home/techb158/cosmic-risk.abdallabala.com/src/app/accept-invite
Edit: /home/techb158/cosmic-risk.abdallabala.com/src/app/accept-invite/page.jsx (3479B)
"use client";
import { Suspense, useState, useEffect } from "react";
import { useRouter, useSearchParams } from "next/navigation";
function AcceptInviteForm() {
const router = useRouter();
const searchParams = useSearchParams();
const token = searchParams.get("token");
const [displayName, setDisplayName] = useState("");
const [error, setError] = useState("");
const [loading, setLoading] = useState(false);
const [done, setDone] = useState(false);
useEffect(() => {
if (!token) setError("No invitation token provided. Check your invite link.");
}, [token]);
async function handleSubmit(event) {
event.preventDefault();
setError("");
setLoading(true);
try {
const res = await fetch("/api/auth/accept-invite", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ token, displayName: displayName || undefined })
});
if (!res.ok) {
const data = await res.json();
throw new Error(data.error || "Failed to accept invitation");
}
setDone(true);
setTimeout(() => router.push("/login"), 2000);
} catch (err) {
setError(err.message);
setLoading(false);
}
}
if (done) {
return (
🎉
Invitation accepted!
Redirecting to login...
);
}
return (
COSMIC AI-Risk SaaS
Accept invitation
You've been invited to join a team.
{error && (
{error}
)}
{token ? (
) : (
Create a new account instead
)}
);
}
export default function AcceptInvitePage() {
return (
}>