Skip to content

Commit

Permalink
add a public getter for logged (#249)
Browse files Browse the repository at this point in the history
* add a public getter for logged

* unifi-client-248 know if a controller is logged or not
  • Loading branch information
thib3113 authored Nov 28, 2021
1 parent 311e119 commit 86ce687
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions src/Controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,15 @@ export class Controller extends ObjectWithPrivateValues implements IController {
private readonly _sites: Sites;
public unifiOs: boolean;
public version?: string = '7.0.0';
private logged: boolean;
private _logged: boolean;

public get logged(): boolean {
return this._logged;
}

private set logged(value: boolean) {
this._logged = value;
}

public createInstance(siteName: string, config?: AxiosRequestConfig): AxiosInstance {
return this._createInstance(siteName, config);
Expand Down Expand Up @@ -115,7 +123,7 @@ export class Controller extends ObjectWithPrivateValues implements IController {
}

private needLoggedIn() {
if (!this.logged) {
if (!this._logged) {
throw new ClientError('you need to login before', EErrorsCodes.NEED_LOGIN);
}
}
Expand All @@ -136,14 +144,14 @@ export class Controller extends ObjectWithPrivateValues implements IController {
//get unifiOs / version / and save logged status
this.unifiOs = this.auth.unifiOs;
this.version = await this.auth.getVersion();
this.logged = true;
this._logged = true;
return user;
}

async logout(): Promise<void> {
await this.auth.logout();
this.auth.autoReLogin = false;
this.logged = false;
this._logged = false;
}

private addAxiosDebugInterceptors(instance: AxiosInstance): AxiosInstance {
Expand Down

0 comments on commit 86ce687

Please sign in to comment.