168 lines
5.2 KiB
TypeScript
168 lines
5.2 KiB
TypeScript
/**
|
|
* Verify Email Page
|
|
*
|
|
* Verify email address with token from email
|
|
*/
|
|
|
|
'use client';
|
|
|
|
import { useState, useEffect } from 'react';
|
|
import { useSearchParams, useRouter } from 'next/navigation';
|
|
import { authApi } from '@/lib/api';
|
|
import Link from 'next/link';
|
|
|
|
export default function VerifyEmailPage() {
|
|
const searchParams = useSearchParams();
|
|
const router = useRouter();
|
|
const [loading, setLoading] = useState(true);
|
|
const [success, setSuccess] = useState(false);
|
|
const [error, setError] = useState('');
|
|
|
|
useEffect(() => {
|
|
const verifyEmail = async () => {
|
|
const token = searchParams.get('token');
|
|
|
|
if (!token) {
|
|
setError('Invalid verification link');
|
|
setLoading(false);
|
|
return;
|
|
}
|
|
|
|
try {
|
|
await authApi.verifyEmail(token);
|
|
setSuccess(true);
|
|
setTimeout(() => {
|
|
router.push('/dashboard');
|
|
}, 3000);
|
|
} catch (err: any) {
|
|
setError(
|
|
err.response?.data?.message ||
|
|
'Email verification failed. The link may have expired.'
|
|
);
|
|
} finally {
|
|
setLoading(false);
|
|
}
|
|
};
|
|
|
|
verifyEmail();
|
|
}, [searchParams, router]);
|
|
|
|
if (loading) {
|
|
return (
|
|
<div className="min-h-screen flex items-center justify-center bg-gray-50">
|
|
<div className="max-w-md w-full space-y-8 text-center">
|
|
<div>
|
|
<h1 className="text-4xl font-bold text-blue-600">Xpeditis</h1>
|
|
<h2 className="mt-6 text-2xl font-bold text-gray-900">
|
|
Verifying your email...
|
|
</h2>
|
|
<div className="mt-4">
|
|
<div className="animate-spin rounded-full h-12 w-12 border-b-2 border-blue-600 mx-auto"></div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
);
|
|
}
|
|
|
|
if (success) {
|
|
return (
|
|
<div className="min-h-screen flex items-center justify-center bg-gray-50 py-12 px-4 sm:px-6 lg:px-8">
|
|
<div className="max-w-md w-full space-y-8">
|
|
<div>
|
|
<h1 className="text-center text-4xl font-bold text-blue-600">
|
|
Xpeditis
|
|
</h1>
|
|
<h2 className="mt-6 text-center text-3xl font-extrabold text-gray-900">
|
|
Email verified successfully!
|
|
</h2>
|
|
</div>
|
|
|
|
<div className="rounded-md bg-green-50 p-4">
|
|
<div className="flex">
|
|
<div className="flex-shrink-0">
|
|
<svg
|
|
className="h-5 w-5 text-green-400"
|
|
xmlns="http://www.w3.org/2000/svg"
|
|
viewBox="0 0 20 20"
|
|
fill="currentColor"
|
|
>
|
|
<path
|
|
fillRule="evenodd"
|
|
d="M10 18a8 8 0 100-16 8 8 0 000 16zm3.707-9.293a1 1 0 00-1.414-1.414L9 10.586 7.707 9.293a1 1 0 00-1.414 1.414l2 2a1 1 0 001.414 0l4-4z"
|
|
clipRule="evenodd"
|
|
/>
|
|
</svg>
|
|
</div>
|
|
<div className="ml-3">
|
|
<p className="text-sm text-green-800">
|
|
Your email has been verified successfully. You will be
|
|
redirected to the dashboard in a few seconds...
|
|
</p>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div className="text-center">
|
|
<Link
|
|
href="/dashboard"
|
|
className="font-medium text-blue-600 hover:text-blue-500"
|
|
>
|
|
Go to dashboard now
|
|
</Link>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
);
|
|
}
|
|
|
|
return (
|
|
<div className="min-h-screen flex items-center justify-center bg-gray-50 py-12 px-4 sm:px-6 lg:px-8">
|
|
<div className="max-w-md w-full space-y-8">
|
|
<div>
|
|
<h1 className="text-center text-4xl font-bold text-blue-600">
|
|
Xpeditis
|
|
</h1>
|
|
<h2 className="mt-6 text-center text-3xl font-extrabold text-gray-900">
|
|
Verification failed
|
|
</h2>
|
|
</div>
|
|
|
|
<div className="rounded-md bg-red-50 p-4">
|
|
<div className="flex">
|
|
<div className="flex-shrink-0">
|
|
<svg
|
|
className="h-5 w-5 text-red-400"
|
|
xmlns="http://www.w3.org/2000/svg"
|
|
viewBox="0 0 20 20"
|
|
fill="currentColor"
|
|
>
|
|
<path
|
|
fillRule="evenodd"
|
|
d="M10 18a8 8 0 100-16 8 8 0 000 16zM8.707 7.293a1 1 0 00-1.414 1.414L8.586 10l-1.293 1.293a1 1 0 101.414 1.414L10 11.414l1.293 1.293a1 1 0 001.414-1.414L11.414 10l1.293-1.293a1 1 0 00-1.414-1.414L10 8.586 8.707 7.293z"
|
|
clipRule="evenodd"
|
|
/>
|
|
</svg>
|
|
</div>
|
|
<div className="ml-3">
|
|
<p className="text-sm text-red-800">{error}</p>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div className="text-center space-y-2">
|
|
<p className="text-sm text-gray-600">
|
|
The verification link may have expired. Please request a new one.
|
|
</p>
|
|
<Link
|
|
href="/login"
|
|
className="block font-medium text-blue-600 hover:text-blue-500"
|
|
>
|
|
Back to sign in
|
|
</Link>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
);
|
|
}
|