Closed bertho-zero closed 6 years ago
// Express async middleware
const wrap = fn => (req, res, next) => Promise.resolve(fn(req, res, next)).catch(next);
wrap(async (req, res, next) => {
const { data } = await app.authenticate('jwt')(req);
req.feathers.user = data.user;
req.feathers.authenticated = !!data.user;
next();
})
Is there a better way than that to get the token from the request? Or ideally recover the user without protecting the route as does the express middleware?
Example
```js app.use('/graphql', (req, res, next) => { req.feathers.token = app.passport._strategies.jwt._jwtFromRequest(req); next(); }, graphqlExpress(({ feathers }) => ({ schema, context: { app, feathers } })) ); ```