Skip to content

Commit

Permalink
feat: expose auth manager
Browse files Browse the repository at this point in the history
  • Loading branch information
davidsl4 committed Nov 15, 2023
1 parent ac8783a commit 980a993
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/AuthManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,23 +33,23 @@ export class AuthManager {
);
}

private get _isUnauthenticated() {
private get isUnauthenticated() {
return !this._accessToken || !this._accessToken.isActive;
}

async _authenticate() {
async authenticate() {
const session = await AuthSession._authenticate(this._apiClient, this._userscriptId);
if (!session.isAuthenticated) throw new Error('Unable to authenticate');
this._accessToken = new JwtToken(session.accessToken);
this._saveAccessTokenInStorage();
}

async _authenticateIfNecessary() {
if (!this._isUnauthenticated && !this.isObsoleteSession) return;
await this._authenticate();
if (!this.isUnauthenticated && !this.isObsoleteSession) return;
await this.authenticate();
}

_logout() {
logout() {
deleteScriptStorageValue(AuthManager._ACCESS_TOKEN_STORAGE_KEY);
this._accessToken = null;
}
Expand Down
5 changes: 5 additions & 0 deletions src/WazeSpaceClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ export class WazeSpaceClient {
await this._apiClient._authManager._authenticateIfNecessary();
}

// noinspection JSUnusedGlobalSymbols
get authManager() {
return this._apiClient._authManager;
}

// noinspection JSUnusedGlobalSymbols
get cloudStorage() {
return this._cloudStorage;
Expand Down

0 comments on commit 980a993

Please sign in to comment.