/node-sequelize

CRUD w/ Sequelize utils NodeJs

Primary LanguageJavaScript

Open Source Made by William Koller

🚀 Technologies

This project was developed with the following technologies:

Routers utils Middleware


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)

Utils middleware w/ JWT

 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()
  })

participants:

name email
William Koller wkoller25@gmail.com

Developers/Contributors :octocat:


William Koller

Made with ♥ by William Koller 👋 Get in touch!