Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/hot-wombats-lick.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@asgardeo/browser': patch
---

Add token refresh logic if the user's access token is expired
2 changes: 1 addition & 1 deletion .github/workflows/pr-builder.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
strategy:
matrix:
node-version: [lts/*]
pnpm-version: [v10]
pnpm-version: [latest]
steps:
- name: ⬇️ Checkout
id: checkout
Expand Down
24 changes: 23 additions & 1 deletion packages/browser/src/__legacy__/helpers/authentication-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -706,6 +706,28 @@ export class AuthenticationHelper<T extends MainThreadClientConfig | WebWorkerCl
}

public async isSignedIn(): Promise<boolean> {
return this._authenticationClient.isSignedIn();
if (await this._authenticationClient.isSignedIn()) {
return true;
}

// A refresh is already in progress — wait for it to finish then re-check.
if (this._isTokenRefreshing) {
await SPAUtils.until(() => !this._isTokenRefreshing);

return this._authenticationClient.isSignedIn();
}

// Token may be expired — attempt a silent refresh before giving up.
try {
this._isTokenRefreshing = true;
await this.refreshAccessToken();
this._isTokenRefreshing = false;

return true;
} catch {
this._isTokenRefreshing = false;

return false;
}
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Comment on lines +709 to +731

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe we could use something like the following version to keep this._authenticationClient.isSignedIn method as the single source for determining the signed in status, instead of explicitly returning boolean status. (haven't tested the following myself though)

public async isSignedIn(): Promise<boolean> {
    if (await this._authenticationClient.isSignedIn()) {
        return this._authenticationClient.isSignedIn();
    }

    if (this._isTokenRefreshing) {
        await SPAUtils.until(() => !this._isTokenRefreshing);

        return this._authenticationClient.isSignedIn();
    }

    try {
        this._isTokenRefreshing = true;
        await this.refreshAccessToken();
    } catch {
        // Ignore refresh failures. Signed-in state is determined below.
    } finally {
        this._isTokenRefreshing = false;
    }

    return this._authenticationClient.isSignedIn();
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better to do this IMO. But +1 to merge the already tested path immediately and later bring this in.

}
}
Loading