Skip to content
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

Correctly conform JWTError to AbortError #162

Merged
merged 8 commits into from
Nov 16, 2024
Merged

Correctly conform JWTError to AbortError #162

merged 8 commits into from
Nov 16, 2024

Conversation

0xTim
Copy link
Member

@0xTim 0xTim commented Nov 3, 2024

These changes are now available in 5.1.1

Make sure JWTError now conforms to AbortError so error messages are returned as expected (and as in v4).

Fixes the token used in the tests so the tests now pass and add back the check for expired.

@0xTim 0xTim requested review from ptoffy and gwynne as code owners November 3, 2024 22:46
@@ -1,6 +1,10 @@
import Vapor

extension JWTError: @retroactive AbortError {
public var reason: String {
Copy link
Member Author

Choose a reason for hiding this comment

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

@gwynne can you see any issues with this given JWTError already has var reason: String? defined? Tbh I'm surprised this actually worked but it seems to and I can't get the compiler to complain about ambiguous types no matter what I try

Copy link
Member

Choose a reason for hiding this comment

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

I think it's a bad idea even if it seems to work, but I don't have an alternate suggestion for having AbortError conformance.

Copy link
Contributor

Choose a reason for hiding this comment

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

Depends what is calling reason. If it thinks the instance is an AbortError, this will be called, otherwise if it thinks it's a JWTError, then the other one will be called.

Copy link
Member Author

Choose a reason for hiding this comment

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

As long at the compiler doesn't see both and get confused we should be fine. The alternative is to wrap the error in our own type and conform that to AbortError - not as nice by far (but then we are only conforming types we own to a protocol rather than types we don't own to protocols we don't own)

@0xTim 0xTim added the semver-patch Internal changes only label Nov 7, 2024
@0xTim 0xTim changed the title Update SIWA Token Correctly conform JWTError to AbortError Nov 7, 2024
@0xTim 0xTim merged commit ec5a9d4 into main Nov 16, 2024
10 checks passed
@0xTim 0xTim deleted the v5-update-siwa branch November 16, 2024 03:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
semver-patch Internal changes only
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants