Skip to content

Fix defaultValidator's time being static#149

Merged
nrktkt merged 3 commits into
blackdoor:masterfrom
longshorej:reuse-validator
Apr 1, 2026
Merged

Fix defaultValidator's time being static#149
nrktkt merged 3 commits into
blackdoor:masterfrom
longshorej:reuse-validator

Conversation

@longshorej

Copy link
Copy Markdown
Contributor

It should be dynamic so that the same instance can be reused over time.

It should be dynamic so that the same instance can be reused over time.
@longshorej

Copy link
Copy Markdown
Contributor Author
Screenshot 2026-03-31 at 4 46 45 PM

@nrktkt nrktkt requested a review from Copilot April 1, 2026 19:03

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes JwtValidator.defaultValidator so its notion of “current time” is evaluated dynamically, allowing a single validator instance to be reused over time without using a stale now.

Changes:

  • Make now dynamic in defaultValidator by switching from a fixed val to a method-based lookup.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 39 to 42
def now = Instant.now(clock)
JwtValidator.fromSync[Any] {
case Jwt(_, claims) if claims.exp.exists(_.isBefore(now)) =>
s"Token expired at ${claims.exp.get}.${iatMessage(claims.iat)} It is now $now."

Copilot AI Apr 1, 2026

Copy link

Choose a reason for hiding this comment

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

now is a def, so it’s evaluated multiple times per validation (in the guard and again when interpolating the error message). That can lead to slightly inconsistent “It is now …” timestamps and performs multiple clock reads. Consider computing val now = Instant.now(clock) once per JWT validation (inside the returned validator function) and reusing it for both the checks and message formatting (e.g., via fromSyncLifted / a total function that returns Option[String]).

Copilot uses AI. Check for mistakes.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

fair, fixed

@nrktkt nrktkt left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

interesting, didn't know that would work.
seems like the type signature would become Jwt => PartialFunciton[Jwt, ...]

@nrktkt nrktkt merged commit dd49990 into blackdoor:master Apr 1, 2026
1 of 2 checks passed
@longshorej longshorej deleted the reuse-validator branch April 1, 2026 22:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants