Ignore:
Timestamp:
01/19/25 23:18:37 (4 months ago)
Author:
Aleksandar Panovski <apano77@…>
Branches:
main
Children:
f5b256e
Parents:
db39d9e
Message:

Done with stupid timeslots

File:
1 edited

Legend:

Unmodified
Added
Removed
  • my-react-app/src/components/Login.js

    rdb39d9e r8ca35dc  
    66    const navigate = useNavigate();
    77    const [credentials, setCredentials] = useState({ username: '', password: '' });
     8    const [error, setError] = useState('');
    89
    910    const handleChange = (e) => {
     
    1516        e.preventDefault();
    1617        try {
    17             const response = await axios.post('http://localhost:8080/api/login', {
     18            const response = await axios.post('http://localhost:8081/api/login', {
    1819                email: credentials.username,
    1920                password: credentials.password
    2021            });
    2122            const { token } = response.data;
    22             // Store token securely (e.g., using HTTP cookies)
     23
     24            // Store token securely (consider httpOnly cookies)
    2325            localStorage.setItem('token', token);
    2426
     
    2729            // Handle login failure
    2830            console.error('Login failed:', error);
     31            setError('Login failed. Please check your credentials and try again.');
    2932        }
    3033    };
    31 
    3234
    3335    return (
     
    5355                    />
    5456                </div>
     57                {error && <div style={{ color: 'red' }}>{error}</div>}
    5558                <button type="submit">Login</button>
    5659            </form>
Note: See TracChangeset for help on using the changeset viewer.