picosam
01/21/2018, 9:07 AMehodges
01/21/2018, 12:16 PMmatic
01/21/2018, 12:59 PMlogan
01/21/2018, 4:10 PMharrisrobin
01/21/2018, 5:04 PMlawjolla
01/22/2018, 3:23 PMpicosam
01/22/2018, 9:09 PMlogan
01/23/2018, 2:45 PMlawjolla
01/23/2018, 11:31 PM<http://server.express.post|server.express.post>(server.options.endpoint, checkJwt)
<http://server.express.post|server.express.post>(server.options.endpoint, (req, res, done) => getUser(req, res, done, db))
checkJwt
is https://github.com/auth0/express-jwt that I put into a middleware folder. If the Bearer token checks, then the request can proceed. If not, the request is stopped. I have it set up to pass on token validation or no token, but it will stop on an improper token.
If it validates, it appends the token to req.user. So the next middleware, getUser...
const getUser = async (req, res, next, db) => {
if (!req.user) return next()
const user = await db.query.user({ where: { auth0id: req.user.sub } })
req.user = { token: req.user, ...user}
next()
}
Now the User object is available to all of your resolvers through context at ctx.request.user
.
Does that make sense to anyone?logan
01/23/2018, 11:47 PMlawjolla
01/23/2018, 11:54 PMlogan
01/23/2018, 11:59 PMehodges
01/24/2018, 5:13 AMlawjolla
01/25/2018, 6:52 PM