Fix login sequence: store token BEFORE calling getCurrentUser
This commit is contained in:
@@ -46,12 +46,14 @@ export const AuthProvider: React.FC<{ children: React.ReactNode }> = ({ children
|
||||
|
||||
const login = async (username: string, password: string) => {
|
||||
const response = await authService.login({ username, password });
|
||||
const userData = await authService.getCurrentUser();
|
||||
|
||||
// CRITICAL: Store token FIRST so axios interceptor can use it
|
||||
localStorage.setItem('token', response.access_token);
|
||||
localStorage.setItem('user', JSON.stringify(userData));
|
||||
|
||||
setToken(response.access_token);
|
||||
|
||||
// NOW fetch user data with the token in place
|
||||
const userData = await authService.getCurrentUser();
|
||||
localStorage.setItem('user', JSON.stringify(userData));
|
||||
setUser(userData);
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user