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

Compilation error with ModelTokenAuthenticatable conformance #780

Open
matthewcheok opened this issue Oct 5, 2024 · 6 comments
Open

Compilation error with ModelTokenAuthenticatable conformance #780

matthewcheok opened this issue Oct 5, 2024 · 6 comments
Labels
bug Something isn't working

Comments

@matthewcheok
Copy link

matthewcheok commented Oct 5, 2024

Describe the issue

I'm getting a compilation error after upgrading to Swift 6.0.1 and Vapor 4.106

Vapor version

4.106.0

Operating system and version

macOS 15.1

Swift version

Swift 6.0.1

Steps to reproduce

Here's the model for my Token entity.

final class Token: Model, @unchecked Sendable {

  init() { }

  init(
    id: UUID? = nil,
    userID: UserModel.IDValue,
    token: String,
    expiresAt: Date?)
  {
    self.id = id
    $user.id = userID
    value = token
    self.expiresAt = expiresAt
  }

  // MARK: Internal

  static let schema = "tokens"

  @ID var id: UUID?

  @Parent(key: "user_id")
  var user: UserModel

  @Field(key: "value")
  var value: String

  @Field(key: "expires_at")
  var expiresAt: Date?

  @Timestamp(key: "created_at", on: .create)
  var createdAt: Date?

}

// Error: Type 'Token' does not conform to protocol 'ModelTokenAuthenticatable'
extension Token: ModelTokenAuthenticatable {
  // Candidate has non-matching type 'any KeyPath<Token, FieldProperty<Token, String>> & Sendable' [with User = <<error type>>]
  static let valueKey = \Token.$value
  static let userKey = \Token.$user

  var isValid: Bool {
    guard let expiryDate = expiresAt else {
      return true
    }

    return expiryDate > Date()
  }
}

Outcome

Errors inline

Additional notes

No response

@matthewcheok matthewcheok added the bug Something isn't working label Oct 5, 2024
@0xTim
Copy link
Member

0xTim commented Oct 5, 2024

@matthewcheok does it work if you change the key paths to

nonisolated(unsafe) static let valueKey = \Token.$value
nonisolated(unsafe) static let userKey = \Token.$user

@matthewcheok
Copy link
Author

Unfortunately that does not work.

Screenshot 2024-10-05 at 7 22 10 PM

@0xTim
Copy link
Member

0xTim commented Oct 5, 2024

I'm assuming UserModel is a sendable model as well? What does the fixit suggest?

@matthewcheok
Copy link
Author

matthewcheok commented Oct 5, 2024 via email

@0xTim
Copy link
Member

0xTim commented Oct 17, 2024

This does look like an issue with ModelTokenAuthenticatable - I'll see if I can come up with a fix

@matthewcheok
Copy link
Author

any updates here?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants