Skip to content
Snippets Groups Projects
Commit 34e3e4bd authored by Giuseppe Digilio's avatar Giuseppe Digilio
Browse files

Fixed issue when reload protected page with expired token

parent 04be7170
No related branches found
No related tags found
No related merge requests found
......@@ -134,8 +134,17 @@ export class AuthService {
* Checks if token is present into storage and is not expired
*/
public checkAuthenticationToken(): Observable<AuthTokenInfo> {
const token = this.getToken();
return isNotEmpty(token) && !this.isTokenExpired() ? Observable.of(token) : Observable.throw(false);
return this.store.select(getAuthenticationToken)
.map((authTokenInfo: AuthTokenInfo) => {
let token: AuthTokenInfo;
// Retrieve authentication token info and check if is valid
token = isNotEmpty(authTokenInfo) ? authTokenInfo : this.storage.get(TOKENITEM);
if (isNotEmpty(token) && token.hasOwnProperty('accessToken') && isNotEmpty(token.accessToken) && !this.isTokenExpired(token)) {
return token;
} else {
throw false;
}
});
}
/**
......@@ -216,10 +225,7 @@ export class AuthService {
this.store.select(getAuthenticationToken)
.subscribe((authTokenInfo: AuthTokenInfo) => {
// Retrieve authentication token info and check if is valid
token = isNotEmpty(authTokenInfo) ? authTokenInfo : this.storage.get(TOKENITEM);
if (isEmpty(token) || !token.hasOwnProperty('accessToken') || isEmpty(token.accessToken)) {
token = null;
}
token = authTokenInfo || null;
});
return token;
}
......@@ -245,8 +251,8 @@ export class AuthService {
* Check if a token is expired
* @returns {boolean}
*/
public isTokenExpired(): boolean {
const token = this.getToken();
public isTokenExpired(token?: AuthTokenInfo): boolean {
token = token || this.getToken();
return token && token.expires < Date.now();
}
......@@ -312,7 +318,6 @@ export class AuthService {
.subscribe((redirectUrl) => {
if (isNotEmpty(redirectUrl)) {
if (this.platform.isBrowser) {
console.log('CLEAR REDIRECT!!!!')
this.clearRedirectUrl();
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment