Make JWT helpers extendable
Pre-release
Pre-release
This patch was authored and released by @tanner0101.
This change publicizes internal properties on JWT helpers to make them more easily extendable (#131, fixes #125).
// Custom extension
extension Request.JWT {
// Methods now have access to the request
func myVerifier() {
print(self._request) // Current request
}
}
// Usage
req.jwt.myVerifier()
The property names have been prefixed with _
to prevent autocomplete from suggesting things like:
req.jwt.request
Application.JWT
and Request.JWT
's initializers have been removed. These were redundant and can be declared much more concisely:
- Application.JWT(application: app)
+ app.jwt
- Request.JWT(request: req)
+ req.jwt