Static GitHub Issues

[1495] Auth Routes from an API

prev: vue-fullpage window is not defined
next: How to get request header using nuxt

Hello support team, I read https://nuxtjs.org/examples/auth-routes and make my project works well. But I want to use API Auth from URL: http://localhost:8000/rest-auth/login/ instead of using username: demo and password: demo. How can I fix file api/index.js

/ Add POST - /api/login
router.post('/login', (req, res) => {
  if (req.body.username === 'demo' && req.body.password === 'demo') {
    req.session.authUser = { username: 'demo' }
    return res.json({ username: 'demo' })
  }
  res.status(401).json({ message: 'Bad credentials' })
})

// Add POST - /api/logout
router.post('/logout', (req, res) => {
  delete req.session.authUser
  res.json({ ok: true })
})

Thank you!

<!--cmty--><!--cmty_prevent_hook--><div align="right"><sub><em>This question is available on <a href="https://nuxtjs.cmty.io">Nuxt.js</a> community (<a href="https://nuxtjs.cmty.io/nuxt/nuxt.js/issues/c1331">#c1331</a>)</em></sub></div>