13 lines
461 B
Swift
13 lines
461 B
Swift
import Vapor
|
|
|
|
struct UserAuthenticator<User: ManagedUser>: AsyncBasicAuthenticator where User.SessionID == ExpiringUserId {
|
|
|
|
func authenticate (basic: BasicAuthorization, for request: Request) async throws {
|
|
if let user = try await request.db.withSQLConnection { connection in
|
|
return try await User.find (email: basic.username, password: basic.password, on: connection)
|
|
} {
|
|
request.auth.login (user)
|
|
}
|
|
}
|
|
}
|