Fix jwt-token

This commit is contained in:
2025-08-18 05:47:56 +02:00
parent 4c67e49621
commit ea76efb3f1
3 changed files with 24 additions and 9 deletions

View File

@@ -68,17 +68,28 @@ export const AuthProvider = ({ children }) => {
const checkAuthStatus = async () => {
try {
dispatch({ type: 'SET_LOADING', payload: true });
const token = localStorage.getItem('token');
if (!token) {
dispatch({ type: 'SET_LOADING', payload: false });
return;
}
const response = await api.get('/users/profile');
dispatch({
type: 'LOGIN_SUCCESS',
payload: {
user: response.data.data,
token: localStorage.getItem('token')
token: token
}
});
} catch (error) {
console.log('Token validation failed:', error.response?.status);
localStorage.removeItem('token');
dispatch({ type: 'LOGOUT' });
} finally {
dispatch({ type: 'SET_LOADING', payload: false });
}
};