Closed addemod closed 4 years ago
You will have a much easier time if you use a factory function instead, then you can use @before(inject(authorize))
.
export function authorize({ tokenManager }) {
return async (req, res, next) => {
try {
const token = await tokenManager.getByAccessToken(getAuthorizationToken(req))
await tokenManager.validate(token.accessToken)
req.token = token
next()
} catch(error) {
next(error)
}
}
function getAuthorizationToken(req) {
// blabla
return "blabla"
}
}
Hello.
I have no idea if this is possible or not, but I can't seem to find a way to make this work. Let's say I have this class:
and I want to use it as a middleware, the question is how? Inside the route class, in
@before
, I cannot use the injectedAuthorizationMiddlewares
class, as I cannot access the route's instance variables. I read something about@inject
but I am not sure if that's the way to go.My route class looks like this:
I am aware that I can import
AuthorizationMiddlewares
directly, but that won't let me inject the token manager class.Please help :)