import { VerifyEmailPage } from '@/features/onboard/verify-email-page';
import { createFileRoute, redirect } from '@tanstack/react-router';
import { z } from 'zod';

const verifyEmailSearchSchema = z.object({
  email: z.string().email().optional(),
});

export const Route = createFileRoute('/onboard/verify-email')({
  validateSearch: verifyEmailSearchSchema,
  beforeLoad: () => {
    const hasPendingSignup = Boolean(sessionStorage.getItem('pending-signup-email'));
    if (!hasPendingSignup) {
      throw redirect({ to: '/onboard' });
    }
  },
  component: VerifyEmailPage,
});
