Fix login sequence: store token BEFORE calling getCurrentUser

This commit is contained in:
2026-01-28 14:59:16 +11:00
parent b36b8e4846
commit b2a9b7ea04

View File

@@ -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);
};