vv
Browse files
frontend/src/pages/Login.jsx
CHANGED
|
@@ -37,9 +37,6 @@ const Login = () => {
|
|
| 37 |
return;
|
| 38 |
}
|
| 39 |
|
| 40 |
-
// Clear any existing errors when component mounts
|
| 41 |
-
dispatch(clearError());
|
| 42 |
-
|
| 43 |
// Only check for cached auth if not already loading
|
| 44 |
if (loading === 'idle') {
|
| 45 |
const checkAuthStatus = async () => {
|
|
@@ -71,6 +68,11 @@ const Login = () => {
|
|
| 71 |
...formData,
|
| 72 |
[e.target.name]: e.target.value
|
| 73 |
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 74 |
};
|
| 75 |
|
| 76 |
const handleFocus = (field) => {
|
|
@@ -95,6 +97,11 @@ const Login = () => {
|
|
| 95 |
return;
|
| 96 |
}
|
| 97 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 98 |
try {
|
| 99 |
const result = await dispatch(loginUser({
|
| 100 |
...formData,
|
|
|
|
| 37 |
return;
|
| 38 |
}
|
| 39 |
|
|
|
|
|
|
|
|
|
|
| 40 |
// Only check for cached auth if not already loading
|
| 41 |
if (loading === 'idle') {
|
| 42 |
const checkAuthStatus = async () => {
|
|
|
|
| 68 |
...formData,
|
| 69 |
[e.target.name]: e.target.value
|
| 70 |
});
|
| 71 |
+
|
| 72 |
+
// Clear error when user starts typing
|
| 73 |
+
if (error) {
|
| 74 |
+
dispatch(clearError());
|
| 75 |
+
}
|
| 76 |
};
|
| 77 |
|
| 78 |
const handleFocus = (field) => {
|
|
|
|
| 97 |
return;
|
| 98 |
}
|
| 99 |
|
| 100 |
+
// Clear any existing errors before attempting login
|
| 101 |
+
if (error) {
|
| 102 |
+
dispatch(clearError());
|
| 103 |
+
}
|
| 104 |
+
|
| 105 |
try {
|
| 106 |
const result = await dispatch(loginUser({
|
| 107 |
...formData,
|
frontend/src/store/reducers/authSlice.js
CHANGED
|
@@ -329,11 +329,11 @@ const authSlice = createSlice({
|
|
| 329 |
name: 'auth',
|
| 330 |
initialState,
|
| 331 |
reducers: {
|
| 332 |
-
|
| 333 |
-
|
| 334 |
-
|
| 335 |
-
|
| 336 |
-
}
|
| 337 |
|
| 338 |
setUser: (state, action) => {
|
| 339 |
state.user = action.payload.user;
|
|
|
|
| 329 |
name: 'auth',
|
| 330 |
initialState,
|
| 331 |
reducers: {
|
| 332 |
+
clearError: (state) => {
|
| 333 |
+
console.log('Clearing Redux error');
|
| 334 |
+
state.error = null;
|
| 335 |
+
state.loading = 'idle';
|
| 336 |
+
},
|
| 337 |
|
| 338 |
setUser: (state, action) => {
|
| 339 |
state.user = action.payload.user;
|