Commit 896537e8 authored by Pearu Sarv's avatar Pearu Sarv
Browse files

TEIS-2499 Update token debugging

parent f4721f51
......@@ -132,8 +132,10 @@ export class AuthenticationService {
return this.refresh;
}
set refreshToken(token: string) {
const previousToken = this.refresh;
this.refresh = token;
localStorage.setItem('refresh_token', token);
this.debugToken(previousToken, token, 'REFRESH_TOKEN');
}
get accessToken(): string {
......@@ -141,9 +143,10 @@ export class AuthenticationService {
}
set accessToken(token: string) {
const previousToken = this.access;
this.access = token;
sessionStorage.setItem('access_token', token);
this.debugToken(token);
this.debugToken(previousToken, token, 'ACCESS_TOKEN');
// TODO: We may only need teis as user object
if (token !== null) {
......@@ -236,7 +239,6 @@ export class AuthenticationService {
* @return {string} Redirect URL
*/
logout(): Observable<string> {
this.debugToken(this.accessToken);
const redirectUrl = this.isMockAuthentication ? this.mockLoginUrl : this.loginUrl;
return of(redirectUrl).pipe(
tap(() => {
......@@ -360,11 +362,22 @@ export class AuthenticationService {
}
}
private debugToken(token: string) {
private debugToken(previousToken: string, newToken: string, type: 'ACCESS_TOKEN' | 'REFRESH_TOKEN') {
if (this.isProduction) {
return;
}
const tokenData = new JwtHelperService().decodeToken(token);
console.debug('Väljastamise aeg (iat):', tokenData?.iat, 'Aegumise aeg (exp):', tokenData?.exp, 'Session ID:', tokenData?.teis?.session_id);
const previousTokenTokenData = new JwtHelperService().decodeToken(previousToken);
const previousIat = previousTokenTokenData?.iat ? new Date(previousTokenTokenData.iat * 1000).toLocaleString() : '-';
const previousExp = previousTokenTokenData?.exp ? new Date(previousTokenTokenData.exp * 1000).toLocaleString() : '-';
const newTokenTokenData = new JwtHelperService().decodeToken(newToken);
const newIat = newTokenTokenData?.iat ? new Date(newTokenTokenData.iat * 1000).toLocaleString() : '-';
const newExp = newTokenTokenData?.exp ? new Date(newTokenTokenData.exp * 1000).toLocaleString() : '-';
console.debug(
`${type} updated:`,
'\n▫ Previous: Väljastamise aeg (iat):', previousIat, 'Aegumise aeg (exp):', previousExp,
'\n▫ New: Väljastamise aeg (iat):', newIat, 'Aegumise aeg (exp):', newExp
);
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment