我尝试将 Vapor AuthMiddleware用于两个实体:客户和商家
https://vapor.github.io/documentation/auth/request.html
let auth = AuthMiddleware(user: Customer.self) { value in
return Cookie(
name: "vapor-auth",
value: value,
expires: Date().addingTimeInterval(60 * 60 * 5),
secure: true,
httpOnly: true
)
}
但正如我所见,如果添加的第一个中间件(客户)被第二个(商家)替换:
drop?.middleware.append(auth)
或者
drop?.addConfigurable(middleware: auth, name: "auth")
因此,如果我尝试通过请求中的凭据登录:
guard let login = req.data["login"]?.string,
let password = req.data["password"]?.string else {
throw Abort.badRequest
}
let credentials = APIKey(id: login, secret: password)
try req.auth.login(credentials)
我有一个错误:
▿ Abort
▿ custom : 2 elements
- .0 : HTTP.Status.badRequest
- .1 : "Invalid credentials."
但它只抛出第一个添加的实体,AuthMiddleware 被其他 AuthMiddleware 替换......
请让我知道是否有可能解决这个问题。谢谢!