Skip to content

Commit

Permalink
feat: authts#4 reduce usage of any type: session_state is typeof string
Browse files Browse the repository at this point in the history
  • Loading branch information
pamapa committed Aug 24, 2021
1 parent c8973f6 commit 5e81347
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 27 deletions.
38 changes: 20 additions & 18 deletions src/CheckSessionIFrame.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export class CheckSessionIFrame {
private _frame: HTMLIFrameElement;
private _boundMessageEvent: ((e: MessageEvent<string>) => void) | null;
private _timer: number | null;
private _session_state: any | null;
private _session_state: string | null;

public constructor(callback: () => Promise<void> | void, client_id: string, url: string, interval?: number, stopOnError?: boolean) {
this._callback = callback;
Expand All @@ -37,7 +37,7 @@ export class CheckSessionIFrame {

this._boundMessageEvent = null;
this._timer = null;

this._session_state = null;
}

public load() {
Expand Down Expand Up @@ -73,28 +73,30 @@ export class CheckSessionIFrame {
}
}

public start(session_state: any) {
if (this._session_state !== session_state) {
Log.debug("CheckSessionIFrame.start");
public start(session_state: string) {
if (this._session_state === session_state) {
return;
}

this.stop();
Log.debug("CheckSessionIFrame.start");

this._session_state = session_state;
this.stop();

const send = () => {
this._frame.contentWindow &&
this._session_state = session_state;

// session_state is unknown... (could likley not be string)
// eslint-disable-next-line @typescript-eslint/restrict-plus-operands
this._frame.contentWindow.postMessage(this._client_id + " " + this._session_state, this._frame_origin);
};
const send = () => {
if (!this._frame.contentWindow || !this._session_state) {
return;
}

// trigger now
send();
this._frame.contentWindow.postMessage(this._client_id + " " + this._session_state, this._frame_origin);
};

// and setup timer
this._timer = window.setInterval(send, this._interval);
}
// trigger now
send();

// and setup timer
this._timer = window.setInterval(send, this._interval);
}

public stop() {
Expand Down
2 changes: 1 addition & 1 deletion src/SessionMonitor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export class SessionMonitor {
}

protected async _start(user: User | {
session_state: any;
session_state: string;
profile: {
sub: string;
sid: string;
Expand Down
8 changes: 4 additions & 4 deletions src/SigninResponse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,23 @@ const OidcScope = "openid";
export class SigninResponse {
public readonly code: string;

// will be set from ResponseValidator
// updated by ResponseValidator
public state: string | undefined;

// will be set from ResponseValidator
// updated by ResponseValidator
public error: string | undefined;
public error_description: string | undefined;
public error_uri: string | undefined;

// will be set from ResponseValidator
// updated by ResponseValidator
public id_token: string | undefined;
public session_state: string | undefined;
public access_token: string | undefined;
public token_type: string | undefined;
public scope: string | undefined;
public expires_at: number | undefined

// will be set from ResponseValidator
// set by ResponseValidator
public profile: any | undefined;

public constructor(url?: string, delimiter = "#") {
Expand Down
6 changes: 3 additions & 3 deletions src/User.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ import { Log, Timer } from "./utils";

export class User {
public id_token: string;
public session_state: any;
public session_state: string | undefined;
public access_token: string;
public refresh_token: string;
public refresh_token: string | undefined;
public token_type: string;
public scope: string;
public profile: any;
public state: any;
public state: any | undefined;
public expires_at: number;

public constructor({
Expand Down
2 changes: 1 addition & 1 deletion src/UserManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -523,7 +523,7 @@ export class UserManager extends OidcClient {
return true;
}

protected async _revokeRefreshTokenInternal(refresh_token: string, required: boolean): Promise<boolean> {
protected async _revokeRefreshTokenInternal(refresh_token: string | undefined, required: boolean): Promise<boolean> {
if (!refresh_token) {
return false;
}
Expand Down

0 comments on commit 5e81347

Please sign in to comment.