Merge pull request 'Issue 21: Fix enforce email format validation and prevent silent form submission blocking' (#24) from fix/issue-21-email-format-validation into main
Reviewed-on: https://10.10.0.4/AcuPedia/acupedia-store-ui/pulls/24 Reviewed-by: Amit Salunke <amit@noreply.localhost>
This commit is contained in:
commit
26419ba194
49
src/App.tsx
49
src/App.tsx
|
|
@ -329,6 +329,33 @@ export default function App() {
|
||||||
setAuthLoading(true);
|
setAuthLoading(true);
|
||||||
setAuthError(null);
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
if (authMode === 'register' && authPhone && authPhone.trim()) {
|
if (authMode === 'register' && authPhone && authPhone.trim()) {
|
||||||
const phoneError = validatePhoneNumber(authPhone, authDialCode, authCountry);
|
const phoneError = validatePhoneNumber(authPhone, authDialCode, authCountry);
|
||||||
if (phoneError) {
|
if (phoneError) {
|
||||||
|
|
@ -365,11 +392,11 @@ export default function App() {
|
||||||
|
|
||||||
const fullPhone = authPhone ? `${authDialCode}${authPhone}` : undefined;
|
const fullPhone = authPhone ? `${authDialCode}${authPhone}` : undefined;
|
||||||
const payload = authMode === 'login'
|
const payload = authMode === 'login'
|
||||||
? { email: authEmail, password: authPassword }
|
? { email: trimmedEmail, password: authPassword }
|
||||||
: {
|
: {
|
||||||
email: authEmail,
|
email: trimmedEmail,
|
||||||
password: authPassword,
|
password: authPassword,
|
||||||
full_name: authDisplayName || undefined,
|
full_name: authDisplayName.trim() || undefined,
|
||||||
phone_number: fullPhone,
|
phone_number: fullPhone,
|
||||||
country: authCountry
|
country: authCountry
|
||||||
};
|
};
|
||||||
|
|
@ -453,9 +480,23 @@ export default function App() {
|
||||||
setAuthError(null);
|
setAuthError(null);
|
||||||
setResetSuccessMessage(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 {
|
try {
|
||||||
const res = await axios.post(`${API_BASE}/api/auth/forgot-password`, {
|
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.');
|
setResetSuccessMessage(res.data.message || 'Verification code sent to your email.');
|
||||||
setResetStep('verify');
|
setResetStep('verify');
|
||||||
|
|
|
||||||
|
|
@ -134,7 +134,7 @@ export const AuthModal: React.FC<AuthModalProps> = ({
|
||||||
{/* Forgot Password Flow */}
|
{/* Forgot Password Flow */}
|
||||||
{authMode === 'forgot' ? (
|
{authMode === 'forgot' ? (
|
||||||
resetStep === 'request' ? (
|
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">
|
<div className="space-y-1.5">
|
||||||
<label className="text-[10px] uppercase font-black tracking-wider text-slate-500">
|
<label className="text-[10px] uppercase font-black tracking-wider text-slate-500">
|
||||||
Registered Email Address
|
Registered Email Address
|
||||||
|
|
@ -171,7 +171,7 @@ export const AuthModal: React.FC<AuthModalProps> = ({
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</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">
|
<div className="space-y-1.5">
|
||||||
<label className="text-[10px] uppercase font-black tracking-wider text-slate-500">
|
<label className="text-[10px] uppercase font-black tracking-wider text-slate-500">
|
||||||
6-Digit Verification Code (OTP)
|
6-Digit Verification Code (OTP)
|
||||||
|
|
@ -249,7 +249,7 @@ export const AuthModal: React.FC<AuthModalProps> = ({
|
||||||
)
|
)
|
||||||
) : (
|
) : (
|
||||||
/* Standard Login & Register Form */
|
/* 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 */}
|
{/* Common: Email */}
|
||||||
<div className="space-y-1.5">
|
<div className="space-y-1.5">
|
||||||
<label className="text-[10px] uppercase font-black tracking-wider text-slate-500">
|
<label className="text-[10px] uppercase font-black tracking-wider text-slate-500">
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue