fix(getUser): prefer stored userinfo over ID token for username claim
Some checks are pending
armco-org/iam-client-sdk/pipeline/head Build queued...

This commit is contained in:
2026-01-26 19:02:13 +05:30
parent 2d76a72910
commit f51f5c8148

View File

@@ -329,9 +329,21 @@ export class StuffleIAMClient {
}
/**
* Get current user from stored ID token
* Get current user from stored userinfo or ID token
* Prefers stored userinfo (from fetchUserInfo) as it has more claims like username
*/
getUser(): User | null {
// First try stored userinfo (has username and other claims from /userinfo endpoint)
const storedUser = this.storage.get(STORAGE_KEYS.USER);
if (storedUser) {
try {
return JSON.parse(storedUser) as User;
} catch {
// Fall through to ID token
}
}
// Fallback to ID token (may not have all claims like username)
const idToken = this.storage.get(STORAGE_KEYS.ID_TOKEN);
if (!idToken) return null;