Show user full name in navbar and homepage after login
All checks were successful
Build frontend / build (push) Successful in 53s

- AuthService: added cacheUser/getCachedUser methods
- AuthService.getUser() prefers cached name over JWT claims
- Login page: fetches full profile from API after login and caches it
- Fixes navbar dropdown and homepage showing email instead of name
This commit is contained in:
Claw AI
2026-03-29 12:42:57 +00:00
parent 253bb875ab
commit 412ccbf8b8
2 changed files with 49 additions and 3 deletions

View File

@ -21,6 +21,7 @@
*/
const TOKEN_KEY = 'auth_token';
const USER_KEY = 'cached_user';
const AuthService = Object.freeze({
addToken(token) {
@ -34,6 +35,28 @@ const AuthService = Object.freeze({
deleteToken() {
localStorage.removeItem(TOKEN_KEY);
localStorage.removeItem(USER_KEY);
},
/**
* Cache full user profile (from API)
* @param {object} user — { name, email, phone, ... }
*/
cacheUser(user) {
if (!user) return;
localStorage.setItem(USER_KEY, JSON.stringify(user));
},
/**
* Get cached user profile
* @returns {object|null}
*/
getCachedUser() {
try {
return JSON.parse(localStorage.getItem(USER_KEY));
} catch {
return null;
}
},
/**
@ -59,11 +82,13 @@ const AuthService = Object.freeze({
const payload = this.decodeToken();
if (!payload) return null;
const cached = this.getCachedUser();
return {
id: payload['http://schemas.xmlsoap.org/ws/2005/05/identity/claims/nameidentifier'] || payload.sub || null,
name: payload['http://schemas.xmlsoap.org/ws/2005/05/identity/claims/name'] || null,
email: payload['http://schemas.xmlsoap.org/ws/2005/05/identity/claims/emailaddress'] || null,
phone: payload['http://schemas.xmlsoap.org/ws/2005/05/identity/claims/mobilephone'] || null,
name: cached?.name || payload['http://schemas.xmlsoap.org/ws/2005/05/identity/claims/name'] || null,
email: cached?.email || payload['http://schemas.xmlsoap.org/ws/2005/05/identity/claims/emailaddress'] || null,
phone: cached?.phone || payload['http://schemas.xmlsoap.org/ws/2005/05/identity/claims/mobilephone'] || null,
roles: this.getRoles(),
};
},