This project was developed with the following technologies:
router.get('/users', authMiddleware, UserController.index)
router.post('/users', UserController.store)
router.put('/users/:user_id', UserController.update)
router.delete('/users/:user_id', UserController.delete)
router.post('/users/login', UserController.login)
router.use(authMiddleware)
router.get('/users/:user_id/address', AddressController.index)
router.post('/users/:user_id/address', AddressController.store)
router.delete('/users/:id/address', AddressController.delete)
router.put('/users/:id/address', AddressController.update)
const authHeader = req.headers.authorization
if (!authHeader) {
return res.status(401).send({ error: 'No token provider' })
}
const parts = authHeader.split(' ')
if (!parts.length == 2) {
return res.status(401).send({ error: 'Token error!' })
}
const [scheme, token] = parts
if (!/^Bearer$/i.test(scheme)) {
return res.status(401).send({ error: 'Token malFormatted' })
}
jwt.verify(token, authConfig.secret, (err, decoded) => {
if (err) return res.status(401).send({ error: 'Token invalid' })
req.userId = decoded.id
console.log(`userId => ${decoded.id}`)
return next()
})
name | |
---|---|
William Koller | wkoller25@gmail.com |
William Koller |
---|
Made with ♥ by William Koller 👋 Get in touch!