All files / web/src/app/auth/error page.tsx

0% Statements 0/155
0% Branches 0/1
0% Functions 0/1
0% Lines 0/155

Press n or j to go to the next uncovered block, b, p or k for the previous block.

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 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156                                                                                                                                                                                                                                                                                                                       
'use client'

import Link from 'next/link'
import { useSearchParams } from 'next/navigation'
import { Suspense } from 'react'
import { css } from '../../../../styled-system/css'
import { useTheme } from '@/contexts/ThemeContext'

const errorMessages: Record<string, { title: string; description: string }> = {
  Configuration: {
    title: 'Server configuration error',
    description:
      'There is a problem with the authentication configuration. Please try again later or contact support.',
  },
  AccessDenied: {
    title: 'Access denied',
    description: 'You do not have permission to sign in. Please try a different account.',
  },
  Verification: {
    title: 'Link expired',
    description: 'The sign-in link has expired or has already been used. Please request a new one.',
  },
  Default: {
    title: 'Something went wrong',
    description: 'An unexpected error occurred during sign-in. Please try again.',
  },
}

function ErrorContent() {
  const { resolvedTheme } = useTheme()
  const isDark = resolvedTheme === 'dark'
  const searchParams = useSearchParams()
  const errorCode = searchParams.get('error') ?? 'Default'
  const { title, description } = errorMessages[errorCode] ?? errorMessages.Default

  return (
    <main
      data-component="auth-error-page"
      className={css({
        minHeight: '100vh',
        display: 'flex',
        alignItems: 'center',
        justifyContent: 'center',
        backgroundColor: isDark ? 'gray.900' : 'gray.50',
        padding: '1rem',
      })}
    >
      <div
        className={css({
          width: '100%',
          maxWidth: '400px',
          padding: '2rem',
          borderRadius: '16px',
          backgroundColor: isDark ? 'gray.800' : 'white',
          border: '1px solid',
          borderColor: isDark ? 'gray.700' : 'gray.200',
          boxShadow: isDark ? '0 8px 24px rgba(0, 0, 0, 0.4)' : '0 8px 24px rgba(0, 0, 0, 0.1)',
          textAlign: 'center',
        })}
      >
        <div
          className={css({
            width: '64px',
            height: '64px',
            margin: '0 auto 1.5rem',
            borderRadius: '50%',
            backgroundColor: isDark ? 'red.900/30' : 'red.50',
            display: 'flex',
            alignItems: 'center',
            justifyContent: 'center',
            fontSize: '2rem',
          })}
        >
          &#x26A0;
        </div>

        <h1
          className={css({
            fontSize: '1.25rem',
            fontWeight: 'bold',
            color: isDark ? 'white' : 'gray.900',
            marginBottom: '0.75rem',
          })}
        >
          {title}
        </h1>

        <p
          className={css({
            fontSize: '0.9375rem',
            color: isDark ? 'gray.400' : 'gray.600',
            lineHeight: '1.5',
            marginBottom: '1.5rem',
          })}
        >
          {description}
        </p>

        <div
          className={css({
            display: 'flex',
            flexDirection: 'column',
            gap: '0.75rem',
          })}
        >
          <Link
            href="/auth/signin"
            data-action="try-again"
            className={css({
              display: 'block',
              padding: '0.75rem 1rem',
              borderRadius: '8px',
              backgroundColor: 'purple.600',
              color: 'white',
              fontSize: '0.9375rem',
              fontWeight: 500,
              textDecoration: 'none',
              textAlign: 'center',
              transition: 'background-color 0.2s ease',
              _hover: {
                backgroundColor: 'purple.700',
              },
            })}
          >
            Try signing in again
          </Link>

          <Link
            href="/"
            data-action="continue-as-guest"
            className={css({
              fontSize: '0.875rem',
              color: isDark ? 'gray.400' : 'gray.500',
              textDecoration: 'none',
              _hover: {
                color: isDark ? 'gray.300' : 'gray.700',
                textDecoration: 'underline',
              },
            })}
          >
            Continue as guest
          </Link>
        </div>
      </div>
    </main>
  )
}

export default function AuthErrorPage() {
  return (
    <Suspense>
      <ErrorContent />
    </Suspense>
  )
}