Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/app/components/user-info/user-info.component.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
<div class="info" label="Username">{{ authService.getUsername() }}</div>
<div class="info" label="Scopes in token">{{ authService.getScopes() }}</div>
<div class="info" label="Access token expires on">{{ get_access_token_expiration() }} ‒ {{ time_to_access_token_expire }}</div>
<div class="info" label="Refresh token expires on">{{ refresh_token_expire() }} ‒ {{ time_to_refresh_token_expire }}
@let accessTokenExpiration = get_access_token_expiration();
@let refreshTokenExpiration = refresh_token_expire();
<div class="info" label="Access token expires on">{{ accessTokenExpiration ? (accessTokenExpiration | date : 'short') : 'undefined' }} ‒ {{ time_to_access_token_expire }}</div>
<div class="info" label="Refresh token expires on">{{ refreshTokenExpiration ? (refreshTokenExpiration | date : 'short') : 'undefined' }} ‒ {{ time_to_refresh_token_expire }}
</div>

@if (usersService.user.isLoading()) {
Expand Down
19 changes: 4 additions & 15 deletions src/app/components/user-info/user-info.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,28 +77,17 @@ export class UserInfoComponent implements OnInit, OnDestroy {
return `${m}:${pad(s)}`;
}

#formatTokenExpirationDate(exp: number): string {
const userLocale = navigator.languages?.[0] || navigator.language || 'cs-CZ';
return new Intl.DateTimeFormat(
userLocale,
{
dateStyle: 'short',
timeStyle: 'medium'
}
).format(new Date(exp * 1000));
}

protected get_access_token_expiration() {
const exp = this.authService.getDecodedAccessToken()?.exp;
if (!exp) return 'undefined';
return this.#formatTokenExpirationDate(exp);
if (!exp) return undefined;
return exp * 1000;
}

protected refresh_token_expire() {
const exp = this.authService.getDecodedRefreshToken()?.exp;
if (!exp) return 'undefined';
if (!exp) return undefined;

return this.#formatTokenExpirationDate(exp);
return exp * 1000;
}

protected readonly show_user_dependended_info = computed<boolean>(() => {
Expand Down