()
| 30 | } |
| 31 | |
| 32 | export default function SSOForm() { |
| 33 | const router = useRouter() |
| 34 | const searchParams = useSearchParams() |
| 35 | const [isLoading, setIsLoading] = useState(false) |
| 36 | const [email, setEmail] = useState('') |
| 37 | const [emailErrors, setEmailErrors] = useState<string[]>([]) |
| 38 | const [showEmailValidationError, setShowEmailValidationError] = useState(false) |
| 39 | const [callbackUrl, setCallbackUrl] = useState('/workspace') |
| 40 | |
| 41 | useEffect(() => { |
| 42 | if (searchParams) { |
| 43 | const callback = searchParams.get('callbackUrl') |
| 44 | if (callback) { |
| 45 | if (validateCallbackUrl(callback)) { |
| 46 | setCallbackUrl(callback) |
| 47 | } else { |
| 48 | logger.warn('Invalid callback URL detected and blocked:', { url: callback }) |
| 49 | } |
| 50 | } |
| 51 | |
| 52 | const emailParam = searchParams.get('email') |
| 53 | if (emailParam) { |
| 54 | setEmail(emailParam) |
| 55 | } |
| 56 | |
| 57 | const error = searchParams.get('error') |
| 58 | if (error) { |
| 59 | const errorMessages: Record<string, string> = { |
| 60 | account_not_found: |
| 61 | 'No account found. Please contact your administrator to set up SSO access.', |
| 62 | sso_failed: 'SSO authentication failed. Please try again.', |
| 63 | invalid_provider: 'SSO provider not configured correctly.', |
| 64 | } |
| 65 | setEmailErrors([errorMessages[error] || 'SSO authentication failed. Please try again.']) |
| 66 | setShowEmailValidationError(true) |
| 67 | } |
| 68 | } |
| 69 | }, [searchParams]) |
| 70 | |
| 71 | const handleEmailChange = (e: React.ChangeEvent<HTMLInputElement>) => { |
| 72 | const newEmail = e.target.value |
| 73 | setEmail(newEmail) |
| 74 | |
| 75 | const errors = validateEmailField(newEmail) |
| 76 | setEmailErrors(errors) |
| 77 | setShowEmailValidationError(false) |
| 78 | } |
| 79 | |
| 80 | async function onSubmit(e: React.FormEvent<HTMLFormElement>) { |
| 81 | e.preventDefault() |
| 82 | setIsLoading(true) |
| 83 | |
| 84 | const formData = new FormData(e.currentTarget) |
| 85 | const emailRaw = formData.get('email') as string |
| 86 | const emailValue = emailRaw.trim().toLowerCase() |
| 87 | |
| 88 | const emailValidationErrors = validateEmailField(emailValue) |
| 89 | setEmailErrors(emailValidationErrors) |
nothing calls this directly
no test coverage detected