fix: Remove HTML5 validation from auth forms
- Add noValidate to forms - Move validation to JS - Add proper autoComplete attributes - Better error messages in Ukrainian
This commit is contained in:
@@ -22,16 +22,42 @@ export default function LoginPage() {
|
|||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const validateForm = (): string | null => {
|
||||||
|
if (!email.trim()) {
|
||||||
|
return 'Введіть email адресу'
|
||||||
|
}
|
||||||
|
// Basic email validation
|
||||||
|
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/
|
||||||
|
if (!emailRegex.test(email)) {
|
||||||
|
return 'Введіть коректну email адресу'
|
||||||
|
}
|
||||||
|
if (!password) {
|
||||||
|
return 'Введіть пароль'
|
||||||
|
}
|
||||||
|
if (password.length < 8) {
|
||||||
|
return 'Пароль повинен містити мінімум 8 символів'
|
||||||
|
}
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
const handleSubmit = async (e: React.FormEvent) => {
|
const handleSubmit = async (e: React.FormEvent) => {
|
||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
setError('')
|
setError('')
|
||||||
|
|
||||||
|
// Client-side validation
|
||||||
|
const validationError = validateForm()
|
||||||
|
if (validationError) {
|
||||||
|
setError(validationError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
setLoading(true)
|
setLoading(true)
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await login(email, password)
|
await login(email, password)
|
||||||
router.push('/')
|
router.push('/')
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
setError(err instanceof Error ? err.message : 'Login failed')
|
setError(err instanceof Error ? err.message : 'Помилка входу. Перевірте дані та спробуйте ще раз.')
|
||||||
} finally {
|
} finally {
|
||||||
setLoading(false)
|
setLoading(false)
|
||||||
}
|
}
|
||||||
@@ -56,7 +82,7 @@ export default function LoginPage() {
|
|||||||
|
|
||||||
{/* Form */}
|
{/* Form */}
|
||||||
<div className="glass-panel p-8">
|
<div className="glass-panel p-8">
|
||||||
<form onSubmit={handleSubmit} className="space-y-6">
|
<form onSubmit={handleSubmit} noValidate className="space-y-6">
|
||||||
{/* Error */}
|
{/* Error */}
|
||||||
{error && (
|
{error && (
|
||||||
<div className="flex items-center gap-2 p-3 bg-red-500/10 border border-red-500/20 rounded-xl text-red-400 text-sm">
|
<div className="flex items-center gap-2 p-3 bg-red-500/10 border border-red-500/20 rounded-xl text-red-400 text-sm">
|
||||||
@@ -78,7 +104,7 @@ export default function LoginPage() {
|
|||||||
value={email}
|
value={email}
|
||||||
onChange={(e) => setEmail(e.target.value)}
|
onChange={(e) => setEmail(e.target.value)}
|
||||||
placeholder="your@email.com"
|
placeholder="your@email.com"
|
||||||
required
|
autoComplete="email"
|
||||||
className={cn(
|
className={cn(
|
||||||
'w-full pl-10 pr-4 py-3 bg-slate-800/50 border border-white/10 rounded-xl',
|
'w-full pl-10 pr-4 py-3 bg-slate-800/50 border border-white/10 rounded-xl',
|
||||||
'text-white placeholder-slate-500',
|
'text-white placeholder-slate-500',
|
||||||
@@ -102,8 +128,7 @@ export default function LoginPage() {
|
|||||||
value={password}
|
value={password}
|
||||||
onChange={(e) => setPassword(e.target.value)}
|
onChange={(e) => setPassword(e.target.value)}
|
||||||
placeholder="••••••••"
|
placeholder="••••••••"
|
||||||
required
|
autoComplete="current-password"
|
||||||
minLength={8}
|
|
||||||
className={cn(
|
className={cn(
|
||||||
'w-full pl-10 pr-4 py-3 bg-slate-800/50 border border-white/10 rounded-xl',
|
'w-full pl-10 pr-4 py-3 bg-slate-800/50 border border-white/10 rounded-xl',
|
||||||
'text-white placeholder-slate-500',
|
'text-white placeholder-slate-500',
|
||||||
|
|||||||
@@ -34,17 +34,30 @@ export default function RegisterPage() {
|
|||||||
const isPasswordValid = passwordRequirements.every(r => r.met)
|
const isPasswordValid = passwordRequirements.every(r => r.met)
|
||||||
const doPasswordsMatch = password === confirmPassword && password.length > 0
|
const doPasswordsMatch = password === confirmPassword && password.length > 0
|
||||||
|
|
||||||
|
const validateForm = (): string | null => {
|
||||||
|
if (!email.trim()) {
|
||||||
|
return 'Введіть email адресу'
|
||||||
|
}
|
||||||
|
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/
|
||||||
|
if (!emailRegex.test(email)) {
|
||||||
|
return 'Введіть коректну email адресу'
|
||||||
|
}
|
||||||
|
if (!isPasswordValid) {
|
||||||
|
return 'Пароль не відповідає вимогам'
|
||||||
|
}
|
||||||
|
if (!doPasswordsMatch) {
|
||||||
|
return 'Паролі не співпадають'
|
||||||
|
}
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
const handleSubmit = async (e: React.FormEvent) => {
|
const handleSubmit = async (e: React.FormEvent) => {
|
||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
setError('')
|
setError('')
|
||||||
|
|
||||||
if (!isPasswordValid) {
|
const validationError = validateForm()
|
||||||
setError('Пароль не відповідає вимогам')
|
if (validationError) {
|
||||||
return
|
setError(validationError)
|
||||||
}
|
|
||||||
|
|
||||||
if (!doPasswordsMatch) {
|
|
||||||
setError('Паролі не співпадають')
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -54,7 +67,7 @@ export default function RegisterPage() {
|
|||||||
await register(email, password, displayName || undefined)
|
await register(email, password, displayName || undefined)
|
||||||
router.push('/')
|
router.push('/')
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
setError(err instanceof Error ? err.message : 'Registration failed')
|
setError(err instanceof Error ? err.message : 'Помилка реєстрації. Спробуйте ще раз.')
|
||||||
} finally {
|
} finally {
|
||||||
setLoading(false)
|
setLoading(false)
|
||||||
}
|
}
|
||||||
@@ -79,7 +92,7 @@ export default function RegisterPage() {
|
|||||||
|
|
||||||
{/* Form */}
|
{/* Form */}
|
||||||
<div className="glass-panel p-8">
|
<div className="glass-panel p-8">
|
||||||
<form onSubmit={handleSubmit} className="space-y-5">
|
<form onSubmit={handleSubmit} noValidate className="space-y-5">
|
||||||
{/* Error */}
|
{/* Error */}
|
||||||
{error && (
|
{error && (
|
||||||
<div className="flex items-center gap-2 p-3 bg-red-500/10 border border-red-500/20 rounded-xl text-red-400 text-sm">
|
<div className="flex items-center gap-2 p-3 bg-red-500/10 border border-red-500/20 rounded-xl text-red-400 text-sm">
|
||||||
@@ -101,7 +114,7 @@ export default function RegisterPage() {
|
|||||||
value={displayName}
|
value={displayName}
|
||||||
onChange={(e) => setDisplayName(e.target.value)}
|
onChange={(e) => setDisplayName(e.target.value)}
|
||||||
placeholder="Ваше ім'я"
|
placeholder="Ваше ім'я"
|
||||||
maxLength={100}
|
autoComplete="name"
|
||||||
className={cn(
|
className={cn(
|
||||||
'w-full pl-10 pr-4 py-3 bg-slate-800/50 border border-white/10 rounded-xl',
|
'w-full pl-10 pr-4 py-3 bg-slate-800/50 border border-white/10 rounded-xl',
|
||||||
'text-white placeholder-slate-500',
|
'text-white placeholder-slate-500',
|
||||||
@@ -125,7 +138,7 @@ export default function RegisterPage() {
|
|||||||
value={email}
|
value={email}
|
||||||
onChange={(e) => setEmail(e.target.value)}
|
onChange={(e) => setEmail(e.target.value)}
|
||||||
placeholder="your@email.com"
|
placeholder="your@email.com"
|
||||||
required
|
autoComplete="email"
|
||||||
className={cn(
|
className={cn(
|
||||||
'w-full pl-10 pr-4 py-3 bg-slate-800/50 border border-white/10 rounded-xl',
|
'w-full pl-10 pr-4 py-3 bg-slate-800/50 border border-white/10 rounded-xl',
|
||||||
'text-white placeholder-slate-500',
|
'text-white placeholder-slate-500',
|
||||||
@@ -149,7 +162,7 @@ export default function RegisterPage() {
|
|||||||
value={password}
|
value={password}
|
||||||
onChange={(e) => setPassword(e.target.value)}
|
onChange={(e) => setPassword(e.target.value)}
|
||||||
placeholder="••••••••"
|
placeholder="••••••••"
|
||||||
required
|
autoComplete="new-password"
|
||||||
className={cn(
|
className={cn(
|
||||||
'w-full pl-10 pr-4 py-3 bg-slate-800/50 border border-white/10 rounded-xl',
|
'w-full pl-10 pr-4 py-3 bg-slate-800/50 border border-white/10 rounded-xl',
|
||||||
'text-white placeholder-slate-500',
|
'text-white placeholder-slate-500',
|
||||||
@@ -188,7 +201,7 @@ export default function RegisterPage() {
|
|||||||
value={confirmPassword}
|
value={confirmPassword}
|
||||||
onChange={(e) => setConfirmPassword(e.target.value)}
|
onChange={(e) => setConfirmPassword(e.target.value)}
|
||||||
placeholder="••••••••"
|
placeholder="••••••••"
|
||||||
required
|
autoComplete="new-password"
|
||||||
className={cn(
|
className={cn(
|
||||||
'w-full pl-10 pr-4 py-3 bg-slate-800/50 border border-white/10 rounded-xl',
|
'w-full pl-10 pr-4 py-3 bg-slate-800/50 border border-white/10 rounded-xl',
|
||||||
'text-white placeholder-slate-500',
|
'text-white placeholder-slate-500',
|
||||||
|
|||||||
Reference in New Issue
Block a user