fix(auth): enforce email format validation and prevent silent form submission blocking
This commit is contained in:
parent
776e09a918
commit
b1f9c45d46
48
src/App.tsx
48
src/App.tsx
|
|
@ -298,14 +298,40 @@ export default function App() {
|
|||
setAuthLoading(true);
|
||||
setAuthError(null);
|
||||
|
||||
const trimmedEmail = authEmail.trim();
|
||||
if (!trimmedEmail) {
|
||||
setAuthError('Email address is required.');
|
||||
setAuthLoading(false);
|
||||
return;
|
||||
}
|
||||
|
||||
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
|
||||
if (!emailRegex.test(trimmedEmail)) {
|
||||
setAuthError('Please enter a valid email address.');
|
||||
setAuthLoading(false);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!authPassword) {
|
||||
setAuthError('Password is required.');
|
||||
setAuthLoading(false);
|
||||
return;
|
||||
}
|
||||
|
||||
if (authMode === 'register' && !authDisplayName.trim()) {
|
||||
setAuthError('Display name is required.');
|
||||
setAuthLoading(false);
|
||||
return;
|
||||
}
|
||||
|
||||
const endpoint = authMode === 'login' ? '/api/auth/login' : '/api/auth/register';
|
||||
const fullPhone = authPhone ? `${authDialCode}${authPhone}` : undefined;
|
||||
const payload = authMode === 'login'
|
||||
? { email: authEmail, password: authPassword }
|
||||
? { email: trimmedEmail, password: authPassword }
|
||||
: {
|
||||
email: authEmail,
|
||||
email: trimmedEmail,
|
||||
password: authPassword,
|
||||
full_name: authDisplayName || undefined,
|
||||
full_name: authDisplayName.trim() || undefined,
|
||||
phone_number: fullPhone,
|
||||
country: authCountry
|
||||
};
|
||||
|
|
@ -389,9 +415,23 @@ export default function App() {
|
|||
setAuthError(null);
|
||||
setResetSuccessMessage(null);
|
||||
|
||||
const trimmedEmail = authEmail.trim();
|
||||
if (!trimmedEmail) {
|
||||
setAuthError('Email address is required.');
|
||||
setAuthLoading(false);
|
||||
return;
|
||||
}
|
||||
|
||||
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
|
||||
if (!emailRegex.test(trimmedEmail)) {
|
||||
setAuthError('Please enter a valid email address.');
|
||||
setAuthLoading(false);
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const res = await axios.post(`${API_BASE}/api/auth/forgot-password`, {
|
||||
email: authEmail
|
||||
email: trimmedEmail
|
||||
});
|
||||
setResetSuccessMessage(res.data.message || 'Verification code sent to your email.');
|
||||
setResetStep('verify');
|
||||
|
|
|
|||
|
|
@ -132,7 +132,7 @@ export const AuthModal: React.FC<AuthModalProps> = ({
|
|||
{/* Forgot Password Flow */}
|
||||
{authMode === 'forgot' ? (
|
||||
resetStep === 'request' ? (
|
||||
<form onSubmit={onForgotPasswordRequest} className="space-y-4 text-left">
|
||||
<form onSubmit={onForgotPasswordRequest} noValidate className="space-y-4 text-left">
|
||||
<div className="space-y-1.5">
|
||||
<label className="text-[10px] uppercase font-black tracking-wider text-slate-500">
|
||||
Registered Email Address
|
||||
|
|
@ -169,7 +169,7 @@ export const AuthModal: React.FC<AuthModalProps> = ({
|
|||
</div>
|
||||
</form>
|
||||
) : (
|
||||
<form onSubmit={onResetPasswordSubmit} className="space-y-4 text-left">
|
||||
<form onSubmit={onResetPasswordSubmit} noValidate className="space-y-4 text-left">
|
||||
<div className="space-y-1.5">
|
||||
<label className="text-[10px] uppercase font-black tracking-wider text-slate-500">
|
||||
6-Digit Verification Code (OTP)
|
||||
|
|
@ -247,7 +247,7 @@ export const AuthModal: React.FC<AuthModalProps> = ({
|
|||
)
|
||||
) : (
|
||||
/* Standard Login & Register Form */
|
||||
<form onSubmit={onAuthSubmit} className="space-y-4 text-left">
|
||||
<form onSubmit={onAuthSubmit} noValidate className="space-y-4 text-left">
|
||||
{/* Common: Email */}
|
||||
<div className="space-y-1.5">
|
||||
<label className="text-[10px] uppercase font-black tracking-wider text-slate-500">
|
||||
|
|
|
|||
Loading…
Reference in New Issue