AgPerry's picture
Add files using upload-large-folder tool
9d4a3b0 verified
Raw History Blame Contribute Delete
2.43 kB
"use client";
import Link from "next/link";
import { useEffect, useState } from "react";
import { CheckCircle2, LoaderCircle, ShieldCheck, XCircle } from "lucide-react";
import { Brand } from "./Brand";
type VerificationState = "verifying" | "verified" | "invalid";
export function VerifyEmail({ token }: { token: string }) {
const [state, setState] = useState<VerificationState>(token ? "verifying" : "invalid");
const [message, setMessage] = useState(token ? "Confirming your email address…" : "This verification link is incomplete.");
useEffect(() => {
if (!token) return;
let active = true;
fetch("/api/auth/verification/confirm", {
method: "POST",
headers: { "content-type": "application/json" },
body: JSON.stringify({ token }),
})
.then(async (response) => {
const result = await response.json() as { error?: string };
if (!response.ok) throw new Error(result.error ?? "This verification link is invalid or expired.");
if (active) {
setState("verified");
setMessage("Your LinkedIn account is verified and ready.");
}
})
.catch((error: unknown) => {
if (active) {
setState("invalid");
setMessage(error instanceof Error ? error.message : "This verification link is invalid or expired.");
}
});
return () => {
active = false;
};
}, [token]);
const Icon = state === "verifying" ? LoaderCircle : state === "verified" ? CheckCircle2 : XCircle;
return (
<main className="auth-page">
<div className="auth-brand"><Brand /></div>
<section className="auth-card auth-status">
<span className={`auth-status-icon ${state}`}><Icon size={30} /></span>
<h1>{state === "verifying" ? "Verifying email" : state === "verified" ? "Email verified" : "Link unavailable"}</h1>
<p role={state === "invalid" ? "alert" : "status"}>{message}</p>
{state === "verified" ? (
<Link prefetch={false} className="button button-primary button-full" href="/feed"><ShieldCheck size={18} /> Continue to LinkedIn</Link>
) : state === "invalid" ? (
<Link prefetch={false} className="button button-outline button-full" href="/login">Return to sign in</Link>
) : null}
</section>
<footer className="auth-footer">LinkedIn © 2026 · Privacy · Terms · Help</footer>
</main>
);
}