Commit ce0ad333 authored by Pearu Sarv's avatar Pearu Sarv
Browse files

Merge branch 'feature/TEIS-2499' into 'develop'

Resolve TEIS-2499 "Feature/"

Closes TEIS-2499

See merge request teis/public-web-client!729
parents eefcb6b3 35f705ff
......@@ -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, 'session_id:', previousTokenTokenData?.teis?.session_id,
'\n▫ New: Väljastamise aeg (iat):', newIat, 'Aegumise aeg (exp):', newExp, 'session_id:', newTokenTokenData?.teis?.session_id,
);
}
}
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