From f51f5c8148acfe74f8ef363860b9190c0383f8aa Mon Sep 17 00:00:00 2001 From: mohiit1502 Date: Mon, 26 Jan 2026 19:02:13 +0530 Subject: [PATCH] fix(getUser): prefer stored userinfo over ID token for username claim --- src/client.ts | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/client.ts b/src/client.ts index 0cab965..5976b12 100644 --- a/src/client.ts +++ b/src/client.ts @@ -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;