Changeset 3ae4bab


Ignore:
Timestamp:
07/02/26 19:57:47 (3 days ago)
Author:
kikisrbinoska <srbinoskakristina07@…>
Branches:
main
Children:
a6e33d1
Parents:
a8f4a2d
Message:

Changes for log in

Files:
3 edited

Legend:

Unmodified
Added
Removed
  • ChapterX.Application/Auth/LoginHandler.cs

    ra8f4a2d r3ae4bab  
    1818        {
    1919            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.");
    2121
    2222            if (!BCrypt.Net.BCrypt.Verify(request.Password, user.Password))
    23                 throw new UnauthorizedAccessException("Invalid email or password.");
     23                throw new UnauthorizedAccessException("Incorrect password. Please try again.");
    2424
    2525            var token = _jwtTokenService.GenerateToken(user);
  • chapterx-frontend/src/pages/auth/LoginPage.tsx

    ra8f4a2d r3ae4bab  
    1616  const [loading, setLoading] = useState(false)
    1717  const [errors, setErrors] = useState<{ email?: string; password?: string }>({})
     18  const [noAccount, setNoAccount] = useState(false)
    1819
    1920  const validate = () => {
    2021    const e: typeof errors = {}
    21     if (!email.trim()) e.email = 'Email or username is required'
     22    if (!email.trim()) e.email = 'Email is required'
    2223    if (!password.trim()) e.password = 'Password is required'
    2324    setErrors(e)
     
    2829    ev.preventDefault()
    2930    if (!validate()) return
     31    setNoAccount(false)
    3032    setLoading(true)
    3133    try {
     
    3436      navigate('/')
    3537    } 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')
    3746    } finally {
    3847      setLoading(false)
     
    5564        <form onSubmit={handleSubmit} className="space-y-4">
    5665          <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>
    5867            <input
    5968              type="text"
    6069              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) }}
    6271              placeholder="you@example.com"
    6372              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 ${
     
    95104        </form>
    96105
    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'}`}>
    98107          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">
    100109            Create one
    101110          </Link>
  • chapterx-frontend/src/store/authStore.ts

    ra8f4a2d r3ae4bab  
    5555          // If the backend responded with an error (4xx/5xx), surface it to the user
    5656          if (err?.response) {
    57             const message = err.response.data?.message || err.response.data || 'Invalid email or password.'
    58             throw new Error(typeof message === 'string' ? message : 'Invalid 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.')
    5959          }
    6060          // Network error / timeout — fall through to mock login
     
    6565          u => u.username === emailOrUsername || u.email === emailOrUsername
    6666        )
    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.')
    6868        set({ currentUser: user, token: null })
    6969      },
Note: See TracChangeset for help on using the changeset viewer.