Skip to content

Commit

Permalink
changed isLoggedIn logic
Browse files Browse the repository at this point in the history
  • Loading branch information
randilfernando committed Dec 25, 2017
1 parent a1a6d93 commit 49c037c
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/modules/auth/providers/auth.provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,22 +37,29 @@ export class AuthProvider {
}

public async isLoggedIn(): Promise<boolean> {
return !!(await this.getAuth());
const auth: Auth = {accessToken: null, refreshToken: null};
if (!this.accessToken && this.authConfig.persistTokensEnabled) {
const accessTokenPromise = this.authConfig.tokenGetter(this.authConfig.accessTokenStorageKey);
const refreshTokenPromise = this.authConfig.tokenGetter(this.authConfig.refreshTokenStorageKey);
[auth.accessToken, auth.refreshToken] = await Promise.all([accessTokenPromise, refreshTokenPromise]);
}

return await this.setAuth(auth);
}

public async logOut(): Promise<boolean> {
return await this.clearAuth();
}

public async setAuth(auth: Auth): Promise<boolean> {
public async setAuth(auth: Auth, persist: boolean = true): Promise<boolean> {
if (auth.accessToken === null || this.accessToken === '') {
return false;
}

this.accessToken = auth.accessToken;
this.refreshToken = auth.refreshToken;

if (this.authConfig.persistTokensEnabled) {
if (persist && this.authConfig.persistTokensEnabled) {
const accessTokenPromise = this.authConfig.tokenSetter(this.authConfig.accessTokenStorageKey, auth.accessToken);
const refreshTokenPromise = this.authConfig.tokenSetter(this.authConfig.refreshTokenStorageKey, auth.refreshToken);
await Promise.all([accessTokenPromise, refreshTokenPromise]);
Expand Down

0 comments on commit 49c037c

Please sign in to comment.