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 ?