I'm getting a crash when I use the middleware in the beta branch of Auth. Specifically when requesting a route which has been protected with basicAuthMiddleware or tokenAuthMiddleware.
Detail
Given a User model which is BasicAuthenticatable:
extension User: BasicAuthenticatable {
static let usernameKey = \User.email
static let passwordKey = \User.password
}
…And a route which uses the middleware:
let authMiddleware = try User.basicAuthMiddleware(using: PlaintextVerifier(), database: .psql)
let group = router.grouped(authMiddleware)
group.get("test"){ req -> String in
return "OK"
}
…Requesting /test results in a crash when DatabaseKit tries to use a nil connection.
Results
DatabaseKit throws an exception in line 21 of /Connection/DatabaseConnection.swift:
extension DatabaseConnection {
/// See `DatabaseConnectable.connect(to:)`
public func connect<D>(to database: DatabaseIdentifier<D>?) -> Future<D.Connection> {
assert(database == nil, "Unexpected \(#function): nil database identifier") // 🚨🚨🚨
assert(self is D.Connection, "Unexpected \(#function): \(self) not \(D.Connection.self)")
return Future(self as! D.Connection)
}
}
Summary
I'm getting a crash when I use the middleware in the beta branch of Auth. Specifically when requesting a route which has been protected with
basicAuthMiddleware
ortokenAuthMiddleware
.Detail
Given a
User
model which isBasicAuthenticatable
:…And a route which uses the middleware:
…Requesting
/test
results in a crash when DatabaseKit tries to use anil
connection.Results
DatabaseKit throws an exception in line 21 of
/Connection/DatabaseConnection.swift
:🚨:
codes.vapor.application (3): Assertion failed: Unexpected connect(to:): nil database identifier
Steps to reproduce
/App/Setup/Configure.swift
/api/v1/register
with correct details (or use the Paw file,api-template.paw
)/api/v1/me
with basic auth details (Get me with basic Auth
in Paw)