Type Method
guardMiddleware(throwing:)
This middleware ensures that an
Authenticatable type A has been authenticated by a previous Middleware or throws an Error. The middlewares that actually perform authentication will not throw errors if they fail to authenticate the user (except in some exceptional cases like malformed data). This allows the middlewares to be composed together to create chains of authentication for multiple user types.static func guardMiddleware(throwing error: any Error = Abort(.unauthorized, reason: "\(Self.self) not authenticated.")) -> any Middleware
Discussion
Use this middleware to protect routes that might not otherwise attempt to access the authenticated user (which always requires prior authentication).
Use Authenticatable.guardMiddleware(...) to create an instance.
Use this middleware in conjunction with other middleware such as BearerAuthenticator and BasicAuthenticator to do the actual authentication.