0

getAccount is Deprecated for MSAL (@azure/msal-angular) and I need to get username after logged in and display it in UI

Coder Guy
  • 87
  • 9

1 Answers1

0

Searching for the same thing, I found this hacky workaround :

get Username(): string {
    let userInfo: AccountInfo = this.msalService.instance.getAllAccounts()[0];
    return userInfo ? userInfo.username : "";
  }

However getAllAccounts(), seems to return all locally stored accounts, and its none of its business if their session is active or not.

Luckily this github issue could clear up ones comprehension about that, plus giving a way to ensure that the stored account has a valid session.