User authenticator

I created a user table with a username, email, password. username and email are unique, Users can log in using their username or email.

when use ModelAuthenticatable, the usernameKey mapping a field, either username or email. How do I make it map two keys?

extension User: ModelAuthenticatable {
   // username & email 
  static let usernameKey = \User.$username
  static let passwordHashKey = \User.$password

  func verify(password: String) throws -> Bool {
    try Bcrypt.verify(password, created: self.password)

I created a separate authenticator, get basic.username, query the database, username and email which match, and then verify whether the password is correct.

how to fix the error ? :joy: :joy: :sweat_smile: :sweat_smile:

You’re going about it the right way with a custom authenticator where you can do an OR query. Do you have Fluent imported in that file to be able to see the filter functions?

1 Like

:joy: I didn’t import fluent.