Skip to content
Draft
Show file tree
Hide file tree
Changes from 4 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/component.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<div class="info" label="Username">{{username}}</div>
<div class="info" label="Scopes">{{scopes}}</div>
<div class="info" label="Access token expires on">{{access_token_expire}} ‒ {{time_to_access_token_expire}}</div>
<div class="info" label="Refresh token expires on">{{refresh_token_expire}} ‒ {{time_to_refresh_token_expire}}</div>
<div class="info" label="Access token expires on">{{access_token_expire | date: date_format}} ‒
{{time_to_access_token_expire | date: "m:ss" : "+0000" }}</div>
<div class="info" label="Refresh token expires on">{{refresh_token_expire | date: date_format}} ‒
{{time_to_refresh_token_expire | date: "d:hh:mm:ss" : "+0000"}}</div>
Copy link

Copilot AI Feb 28, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The countdown values are being represented as new Date(at_diff) / new Date(rt_diff) and then formatted with the date pipe. This treats the remaining milliseconds as an absolute timestamp since the Unix epoch, which leads to incorrect duration rendering (minutes wrap every hour, and d is day-of-month rather than “days remaining”). Consider keeping the prior explicit duration formatting logic or introducing a dedicated “duration” formatter (pipe/helper) that formats a millisecond delta into d hh:mm:ss reliably.

Suggested change
{{time_to_refresh_token_expire | date: "d:hh:mm:ss" : "+0000"}}</div>
{{time_to_refresh_token_expire | date: "HH:mm:ss" : "+0000"}}</div>

Copilot uses AI. Check for mistakes.
70 changes: 21 additions & 49 deletions src/app/components/user-info/component.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Component, inject, OnDestroy } from "@angular/core";
import { Component, inject, Input, OnDestroy, OnInit } from "@angular/core";
import { AuthService } from "src/app/services/auth.service";

@Component({
Expand All @@ -7,14 +7,16 @@ import { AuthService } from "src/app/services/auth.service";
styleUrls: ['./component.scss'],
standalone: false,
})
export class UserInfoComponent implements OnDestroy {
export class UserInfoComponent implements OnInit, OnDestroy {
readonly #auth = inject(AuthService);
time_to_access_token_expire: string = "";
time_to_refresh_token_expire: string = "";
time_to_access_token_expire: Date = new Date();
time_to_refresh_token_expire: Date = new Date();
#refreshingInterval: number | null = null;

constructor() {
this.#refreshingInterval = window.setInterval(() => { this.#updateCountdown(); }, 1_000)
@Input() date_format: string = 'medium';
Copy link

Copilot AI Feb 28, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

date_format as an @Input name (and corresponding attribute) deviates from the codebase’s existing camelCase input naming (e.g., autosaveDebounce, placeholder). Consider renaming this input to dateFormat and updating call sites accordingly for consistency and to better align with Angular style.

Suggested change
@Input() date_format: string = 'medium';
@Input() dateFormat: string = 'medium';

Copilot uses AI. Check for mistakes.

ngOnInit(): void {
this.#refreshingInterval = window.setInterval(() => { this.#updateCountdown(); }, 1_000);
this.#updateCountdown();
}

ngOnDestroy(): void {
Expand All @@ -25,45 +27,31 @@ export class UserInfoComponent implements OnDestroy {
const at_exp = this.#auth.getDecodedAccessToken()?.exp as number | undefined;
const rt_exp = this.#auth.getDecodedRefreshToken()?.exp as number | undefined;
if (!at_exp) {
this.time_to_access_token_expire = 'exp is not defined';
this.time_to_access_token_expire = new Date();
return;
}
if (!rt_exp) {
this.time_to_refresh_token_expire = 'exp is not defined';
this.time_to_refresh_token_expire = new Date();
return;
Copy link

Copilot AI Feb 28, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When at_exp/rt_exp are missing, the code sets time_to_*_expire to new Date(), which will render as “now” (misleading). Prefer a sentinel like null plus a template fallback (e.g., "exp is not defined") or a separate status field.

Copilot uses AI. Check for mistakes.
}
Copy link

Copilot AI Feb 28, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The early return when at_exp is missing prevents the refresh-token countdown from updating (and vice versa). Update access/refresh countdowns independently so one missing/expired token doesn’t leave the other field stale.

Copilot uses AI. Check for mistakes.

const now = Math.floor(Date.now() / 1000);
const at_diff = at_exp - now;
const rt_diff = rt_exp - now;
const now = Date.now();
const at_diff = (at_exp * 1_000) - now;
const rt_diff = (rt_exp * 1_000) - now;

if (at_diff <= 0) {
this.time_to_access_token_expire = 'EXPIRED';
this.time_to_access_token_expire = new Date();
return;
}

if (rt_diff <= 0) {
this.time_to_refresh_token_expire = 'EXPIRED';
this.time_to_refresh_token_expire = new Date();
return;
Copy link

Copilot AI Feb 28, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When the countdown is expired (*_diff <= 0), time_to_*_expire is set to new Date(), which will render as a valid time/duration instead of “EXPIRED”. Prefer null plus a fallback string (or a dedicated status field) so the UI reflects the expired state accurately.

Copilot uses AI. Check for mistakes.
}

this.time_to_access_token_expire = this.#formatCountdown(at_diff);
this.time_to_refresh_token_expire = this.#formatCountdown(rt_diff);
}

#formatCountdown(totalSeconds: number): string {
const s = totalSeconds % 60;
const mTotal = (totalSeconds - s) / 60;
const m = mTotal % 60;
const hTotal = (mTotal - m) / 60;
const h = hTotal % 24;
const d = (hTotal - h) / 24;

const pad = (n: number) => n.toString().padStart(2, '0');

if (d > 0) return `${d} d ${h}:${pad(m)}:${pad(s)}`;
if (h > 0) return `${h}:${pad(m)}:${pad(s)}`;
return `${m}:${pad(s)}`;
this.time_to_access_token_expire = new Date(at_diff);
this.time_to_refresh_token_expire = new Date(rt_diff);
console.log(this.time_to_refresh_token_expire, rt_exp, rt_diff);
Copy link

Copilot AI Feb 28, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Leftover console.log(...) in #updateCountdown() will spam the console every second and can leak token timing data. Please remove this or replace it with an appropriate, gated logging mechanism.

Suggested change
console.log(this.time_to_refresh_token_expire, rt_exp, rt_diff);

Copilot uses AI. Check for mistakes.
}

get username(): string {
Expand All @@ -87,28 +75,12 @@ export class UserInfoComponent implements OnDestroy {
get access_token_expire() {
const exp = this.#auth.getDecodedAccessToken()?.exp;
if (!exp) return 'undefined';

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

Copilot AI Feb 28, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

access_token_expire returns the string 'undefined' when exp is missing, but the template now pipes access_token_expire through the date pipe. Piping a non-date value can trigger an InvalidPipeArgument runtime error. Return null/undefined (or Date | null) instead and handle the missing case in the template.

Copilot uses AI. Check for mistakes.
}

get refresh_token_expire() {
const exp = this.#auth.getDecodedRefreshToken()?.exp;
if (!exp) return 'undefined';

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

Copilot AI Feb 28, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

refresh_token_expire returns the string 'undefined' when exp is missing, but the template pipes it through the date pipe. Return null/undefined (or Date | null) and render a non-piped fallback string in the template for the missing case.

Copilot uses AI. Check for mistakes.
}
}
2 changes: 1 addition & 1 deletion src/app/user-profile/user-profile.component.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<div class="details">
<h1>User details</h1>
<app-user-info></app-user-info>
<app-user-info date_format="full"></app-user-info>
Copy link

Copilot AI Feb 28, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Passing date_format as a component attribute introduces a snake_case input name that appears inconsistent with other component inputs in this codebase (which use camelCase). If the input is renamed to dateFormat, update this usage as well.

Suggested change
<app-user-info date_format="full"></app-user-info>
<app-user-info dateFormat="full"></app-user-info>

Copilot uses AI. Check for mistakes.
</div>

<div class="details">
Expand Down