Skip to content

Commit

Permalink
fix: honor disableIdle flag (#809)
Browse files Browse the repository at this point in the history
Closes #576

Co-authored-by: Kyle Peacock <[email protected]>
  • Loading branch information
ncpenke and krpeacock authored Dec 1, 2023
1 parent f14a8fb commit 40d9800
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 13 deletions.
4 changes: 3 additions & 1 deletion docs/generated/changelog.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ <h1>Agent-JS Changelog</h1>

<section>
<h2>Version x.x.x</h2>
<ul></ul>
<ul>
<li>fix: honor disableIdle flag</li>
</ul>
<h2>Version 0.20.2</h2>
<ul>
<li>chore: lowering prettier version for CI</li>
Expand Down
24 changes: 12 additions & 12 deletions packages/auth-client/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -329,15 +329,18 @@ export class AuthClient {
// The event handler for processing events from the IdP.
private _eventHandler?: (event: MessageEvent) => void,
) {
const logout = this.logout.bind(this);
const idleOptions = _createOptions?.idleOptions;
this._registerDefaultIdleCallback();
}

private _registerDefaultIdleCallback() {
const idleOptions = this._createOptions?.idleOptions;
/**
* Default behavior is to clear stored identity and reload the page.
* By either setting the disableDefaultIdleCallback flag or passing in a custom idle callback, we will ignore this config
*/
if (!idleOptions?.onIdle && !idleOptions?.disableDefaultIdleCallback) {
this.idleManager?.registerCallback(() => {
logout();
this.logout();
location.reload();
});
}
Expand Down Expand Up @@ -372,17 +375,14 @@ export class AuthClient {
this._identity = DelegationIdentity.fromDelegation(key, this._chain);

this._idpWindow?.close();
if (!this.idleManager) {
const idleOptions = this._createOptions?.idleOptions;
const idleOptions = this._createOptions?.idleOptions;
// create the idle manager on a successful login if we haven't disabled it
// and it doesn't already exist.
if (!this.idleManager && !idleOptions?.disableIdle) {
this.idleManager = IdleManager.create(idleOptions);

if (!idleOptions?.onIdle && !idleOptions?.disableDefaultIdleCallback) {
this.idleManager?.registerCallback(() => {
this.logout();
location.reload();
});
}
this._registerDefaultIdleCallback();
}

this._removeEventListener();
delete this._idpWindow;

Expand Down

0 comments on commit 40d9800

Please sign in to comment.