Static GitHub Issues

[1663] Get Authentication by Django POST API

prev: import router from '~router' stopped working
next: Proper strategy for binding a class to <html>

How can I get Authentication, Storage Sessions with Django API by POST? This example https://nuxtjs.org/examples/auth-routes cant help me. It's logged in success but when reload page it not logged in anymore.

Action Store Login

async login ({ commit }, { username, password }) { try { const { data } = await **axios.post('http://localhost:8000/api/v1/api-token-auth/login'**, { username, password }) commit('SET_USER', data) } catch (error) { if (error.response && error.response.status === 401) { throw new Error('Bad credentials') } throw error } }, ServerMiddleware auth.js router.post('/login', (req, res) => { if (req.body.username && req.body.username == req.body.password) { req.session.authUser = { username } return res.json({ username }) } res.status(401).json({ message: 'Wrong username or Password. Please try again!' }) })

Please help. Thanks in advance

<!--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/c1488">#c1488</a>)</em></sub></div>