Changeset 3ae4bab
- Timestamp:
- 07/02/26 19:57:47 (3 days ago)
- Branches:
- main
- Children:
- a6e33d1
- Parents:
- a8f4a2d
- Files:
-
- 3 edited
-
ChapterX.Application/Auth/LoginHandler.cs (modified) (1 diff)
-
chapterx-frontend/src/pages/auth/LoginPage.tsx (modified) (5 diffs)
-
chapterx-frontend/src/store/authStore.ts (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
ChapterX.Application/Auth/LoginHandler.cs
ra8f4a2d r3ae4bab 18 18 { 19 19 var user = await _userRepository.GetByEmailAsync(request.Email, cancellationToken) 20 ?? throw new UnauthorizedAccessException(" Invalid email or password.");20 ?? throw new UnauthorizedAccessException("No account found with this email. Please register first."); 21 21 22 22 if (!BCrypt.Net.BCrypt.Verify(request.Password, user.Password)) 23 throw new UnauthorizedAccessException("In valid email or password.");23 throw new UnauthorizedAccessException("Incorrect password. Please try again."); 24 24 25 25 var token = _jwtTokenService.GenerateToken(user); -
chapterx-frontend/src/pages/auth/LoginPage.tsx
ra8f4a2d r3ae4bab 16 16 const [loading, setLoading] = useState(false) 17 17 const [errors, setErrors] = useState<{ email?: string; password?: string }>({}) 18 const [noAccount, setNoAccount] = useState(false) 18 19 19 20 const validate = () => { 20 21 const e: typeof errors = {} 21 if (!email.trim()) e.email = 'Email or usernameis required'22 if (!email.trim()) e.email = 'Email is required' 22 23 if (!password.trim()) e.password = 'Password is required' 23 24 setErrors(e) … … 28 29 ev.preventDefault() 29 30 if (!validate()) return 31 setNoAccount(false) 30 32 setLoading(true) 31 33 try { … … 34 36 navigate('/') 35 37 } catch (err: any) { 36 addToast(err.message || 'Login failed', 'error') 38 const message = err?.message || 'Incorrect email or password. Please try again.' 39 if (/no account found/i.test(message)) { 40 setNoAccount(true) 41 setErrors(p => ({ ...p, email: message })) 42 } else { 43 setErrors(p => ({ ...p, password: message })) 44 } 45 addToast(message, 'error') 37 46 } finally { 38 47 setLoading(false) … … 55 64 <form onSubmit={handleSubmit} className="space-y-4"> 56 65 <div> 57 <label className="block text-sm text-slate-400 mb-1.5"> Email or Username</label>66 <label className="block text-sm text-slate-400 mb-1.5">Login with Email</label> 58 67 <input 59 68 type="text" 60 69 value={email} 61 onChange={e => { setEmail(e.target.value); setErrors(p => ({ ...p, email: '' })) }}70 onChange={e => { setEmail(e.target.value); setErrors(p => ({ ...p, email: '' })); setNoAccount(false) }} 62 71 placeholder="you@example.com" 63 72 className={`w-full px-4 py-3 bg-slate-800 border rounded-xl text-white placeholder-slate-500 focus:outline-none focus:border-indigo-500 transition-colors ${ … … 95 104 </form> 96 105 97 <p className= "text-center text-slate-500 text-sm mt-6">106 <p className={`text-center text-sm mt-6 ${noAccount ? 'text-rose-400' : 'text-slate-500'}`}> 98 107 Don't have an account?{' '} 99 <Link to="/register" className="text-indigo-400 hover:text-indigo-300 ">108 <Link to="/register" className="text-indigo-400 hover:text-indigo-300 font-medium"> 100 109 Create one 101 110 </Link> -
chapterx-frontend/src/store/authStore.ts
ra8f4a2d r3ae4bab 55 55 // If the backend responded with an error (4xx/5xx), surface it to the user 56 56 if (err?.response) { 57 const message = err.response.data?.message || err.response.data || 'In valid email or password.'58 throw new Error(typeof message === 'string' ? message : 'In valid email or password.')57 const message = err.response.data?.message || err.response.data || 'Incorrect email or password. Please try again.' 58 throw new Error(typeof message === 'string' ? message : 'Incorrect email or password. Please try again.') 59 59 } 60 60 // Network error / timeout — fall through to mock login … … 65 65 u => u.username === emailOrUsername || u.email === emailOrUsername 66 66 ) 67 if (!user) throw new Error(' User not found. Try using a quick-login option.')67 if (!user) throw new Error('No account found with this email. Please register first.') 68 68 set({ currentUser: user, token: null }) 69 69 },
Note:
See TracChangeset
for help on using the changeset viewer.
