-
Notifications
You must be signed in to change notification settings - Fork 1
fix: use datepipe for date formating #115
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
The head ref may contain hidden characters: "114-pou\u017E\u00EDvat-date-pipe-na-zobrazen\u00ED-expirace-token\u016F"
Changes from 4 commits
0a7a208
f99a0e4
c992fd5
dd02cea
4aa9e9a
d04e868
e253cc0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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> | ||
| 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({ | ||||||
|
|
@@ -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'; | ||||||
|
||||||
| @Input() date_format: string = 'medium'; | |
| @Input() dateFormat: string = 'medium'; |
Outdated
Copilot
AI
Feb 28, 2026
There was a problem hiding this comment.
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.
Outdated
Copilot
AI
Feb 28, 2026
There was a problem hiding this comment.
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.
Outdated
Copilot
AI
Feb 28, 2026
There was a problem hiding this comment.
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.
Outdated
Copilot
AI
Feb 28, 2026
There was a problem hiding this comment.
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.
| console.log(this.time_to_refresh_token_expire, rt_exp, rt_diff); |
Outdated
Copilot
AI
Feb 28, 2026
There was a problem hiding this comment.
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.
Outdated
Copilot
AI
Feb 28, 2026
There was a problem hiding this comment.
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.
| 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> | ||||||
|
||||||
| <app-user-info date_format="full"></app-user-info> | |
| <app-user-info dateFormat="full"></app-user-info> |
There was a problem hiding this comment.
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 thedatepipe. This treats the remaining milliseconds as an absolute timestamp since the Unix epoch, which leads to incorrect duration rendering (minutes wrap every hour, anddis 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 intod hh:mm:ssreliably.