Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mitigate noAccountError #2098678 #5529

Merged
merged 2 commits into from
Jan 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "patch",
"comment": "Log number of accounts in trace mode. #5529",
"packageName": "@azure/msal-browser",
"email": "kshabelko@microsoft.com",
"dependentChangeType": "patch"
}
20 changes: 11 additions & 9 deletions lib/msal-browser/src/cache/BrowserCacheManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -403,33 +403,33 @@ export class BrowserCacheManager extends CacheManager {
getActiveAccount(): AccountInfo | null {
const activeAccountKeyFilters = this.generateCacheKey(PersistentCacheKeys.ACTIVE_ACCOUNT_FILTERS);
const activeAccountValueFilters = this.getItem(activeAccountKeyFilters);
if (!activeAccountValueFilters) {
if (!activeAccountValueFilters) {
// if new active account cache type isn't found, it's an old version, so look for that instead
this.logger.trace("No active account filters cache schema found, looking for legacy schema");
this.logger.trace("BrowserCacheManager.getActiveAccount: No active account filters cache schema found, looking for legacy schema");
const activeAccountKeyLocal = this.generateCacheKey(PersistentCacheKeys.ACTIVE_ACCOUNT);
const activeAccountValueLocal = this.getItem(activeAccountKeyLocal);
if(!activeAccountValueLocal) {
this.logger.trace("No active account found");
this.logger.trace("BrowserCacheManager.getActiveAccount: No active account found");
return null;
}
const activeAccount = this.getAccountInfoByFilter({localAccountId: activeAccountValueLocal})[0] || null;
if(activeAccount) {
this.logger.trace("Legacy active account cache schema found");
this.logger.trace("Adding active account filters cache schema");
this.logger.trace("BrowserCacheManager.getActiveAccount: Legacy active account cache schema found");
this.logger.trace("BrowserCacheManager.getActiveAccount: Adding active account filters cache schema");
this.setActiveAccount(activeAccount);
return activeAccount;
}
return null;
}
const activeAccountValueObj = this.validateAndParseJson(activeAccountValueFilters) as AccountInfo;
if(activeAccountValueObj) {
this.logger.trace("Active account filters schema found");
this.logger.trace("BrowserCacheManager.getActiveAccount: Active account filters schema found");
return this.getAccountInfoByFilter({
homeAccountId: activeAccountValueObj.homeAccountId,
localAccountId: activeAccountValueObj.localAccountId
})[0] || null;
}
this.logger.trace("No active account found");
this.logger.trace("BrowserCacheManager.getActiveAccount: No active account found");
return null;
}

Expand Down Expand Up @@ -461,6 +461,8 @@ export class BrowserCacheManager extends CacheManager {
*/
getAccountInfoByFilter(accountFilter: Partial<Omit<AccountInfo, "idTokenClaims"|"name">>): AccountInfo[] {
const allAccounts = this.getAllAccounts();
this.logger.trace(`BrowserCacheManager.getAccountInfoByFilter: total ${allAccounts.length} accounts found`);

return allAccounts.filter((accountObj) => {
if (accountFilter.username && accountFilter.username.toLowerCase() !== accountObj.username.toLowerCase()) {
return false;
Expand Down Expand Up @@ -1069,10 +1071,10 @@ export class BrowserCacheManager extends CacheManager {
getRedirectRequestContext(): string | null {
return this.getTemporaryCache(TemporaryCacheKeys.REDIRECT_CONTEXT, true);
}

/**
* Sets application id as the redirect context during AcquireTokenRedirect flow.
* @param value
* @param value
*/
setRedirectRequestContext(value: string): void {
this.setTemporaryCache(TemporaryCacheKeys.REDIRECT_CONTEXT, value, true);
Expand Down