fix: fetch full profile after login so header shows display name without refresh

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
Usman Baig
2026-02-08 21:21:59 +01:00
parent bd2aca7a76
commit 0f7e644f17

View File

@@ -53,6 +53,20 @@ export function AuthProvider({ children }: { children: React.ReactNode }) {
localStorage.setItem('user', JSON.stringify(userData))
setUser(userData)
router.refresh()
// * Fetch full profile (including display_name) so header shows correct name without page refresh
apiRequest<User>('/auth/user/me')
.then((fullProfile) => {
setUser((prev) => {
const merged = {
...fullProfile,
org_id: prev?.org_id ?? fullProfile.org_id,
role: prev?.role ?? fullProfile.role,
}
localStorage.setItem('user', JSON.stringify(merged))
return merged
})
})
.catch((e) => console.error('Failed to fetch full profile after login', e))
}
const logout = useCallback(async () => {