From b2a9b7ea04566770f26c9624b8f4305e11a40639 Mon Sep 17 00:00:00 2001 From: jessikitty Date: Wed, 28 Jan 2026 14:59:16 +1100 Subject: [PATCH] Fix login sequence: store token BEFORE calling getCurrentUser --- frontend/src/contexts/AuthContext.tsx | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/frontend/src/contexts/AuthContext.tsx b/frontend/src/contexts/AuthContext.tsx index 262a4d1..e1b4146 100644 --- a/frontend/src/contexts/AuthContext.tsx +++ b/frontend/src/contexts/AuthContext.tsx @@ -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); };