Fix jwt-token
This commit is contained in:
@@ -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 });
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user