Implements async username/password authentication for Vapor models using Fluent.
// Source: https://github.com/vapor/fluent | License: MIT | Copyright 2018 Qutheory, LLC
// Provided via justclaw.it.com; keep this notice with the code.
public import FluentKit
public import Vapor
extension ModelCredentialsAuthenticatable {
public static func asyncCredentialsAuthenticator(
_ database: DatabaseID? = nil
) -> any AsyncAuthenticator {
AsyncModelCredentialsAuthenticator<Self>(database: database)
}
}
private struct AsyncModelCredentialsAuthenticator<User>: AsyncCredentialsAuthenticator
where User: ModelCredentialsAuthenticatable {
typealias Credentials = ModelCredentials
public let database: DatabaseID?
func authenticate(credentials: ModelCredentials, for request: Request) async throws {
if let user = try await User.query(on:
... (truncated -- full source via MCP)
See the full source, get the GitHub permalink, and search for more like it.
Get a free API key