import { type Component, createSignal, onMount, Match, Switch } from 'solid-js'; import { useSearchParams, useNavigate, A } from '@solidjs/router'; import { CheckCircle, XCircle } from 'lucide-solid'; import { authApi } from '~/api/auth'; import { useAuth } from '~/contexts/AuthContext'; import { useI18n } from '~/i18n'; import LoadingSpinner from '~/components/ui/LoadingSpinner'; /** * Magic-link verification page reached via `/auth/verify?token=...`. * * On mount, the `token` query parameter is extracted from the URL. If present, * it is POSTed to the backend's verify endpoint which sets a session cookie. * On success the auth context is refreshed and the user is redirected home * after a 1.5-second delay. Missing or invalid tokens display an error with * a link back to the login page. */ const AuthVerify: Component = () => { const [searchParams] = useSearchParams(); const navigate = useNavigate(); const { refreshUser } = useAuth(); const { t } = useI18n(); const [status, setStatus] = createSignal<'verifying' | 'success' | 'error'>( 'verifying', ); onMount(async () => { const token = searchParams.token; if (!token || typeof token !== 'string') { setStatus('error'); return; } try { await authApi.verify(token); await refreshUser(); setStatus('success'); setTimeout(() => navigate('/', { replace: true }), 1500); } catch { setStatus('error'); } }); return (
{t('auth.verifying')}
{t('auth.verifyErrorDescription')}
{t('auth.backToLogin')}