File size: 2,426 Bytes
062a991
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
"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>
  );
}