Last active
August 9, 2020 09:22
-
-
Save Adarshreddyash/1776094bb78f8bb4e251f122598b380c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //add to store/index.js | |
| import Vue from 'vue' | |
| import Vuex from 'vuex' | |
| import axios from 'axios' | |
| Vue.use(Vuex) | |
| // Make Axios good with django csrf | |
| axios.defaults.xsrfCookieName = 'csrftoken' | |
| axios.defaults.xsrfHeaderName = 'X-CSRFToken' | |
| export default new Vuex.Store({ | |
| state: { | |
| authUser: {}, | |
| isAuthenticated: false, | |
| jwt: localStorage.getItem('token'), | |
| APIData:'', | |
| endpoints: { | |
| // Change these with your endpoints. | |
| obtainJWT: 'https://127.0.0.1/api/v1/auth/obtain_token/', | |
| refreshJWT: 'https://127.0.0.1/api/v1/auth/refresh_token/', | |
| baseUrl: 'https://127.0.0.1/' | |
| } | |
| }, | |
| mutations: { | |
| setAuthUser(state, { | |
| authUser, | |
| isAuthenticated | |
| }) { | |
| Vue.set(state, 'authUser', authUser) | |
| Vue.set(state, 'isAuthenticated', isAuthenticated) | |
| }, | |
| //You should find a better alternative to storing in local storage | |
| updateToken(state, newToken) { | |
| localStorage.setItem('token', newToken); | |
| state.jwt = newToken; | |
| }, | |
| removeToken(state) { | |
| localStorage.removeItem('token'); | |
| state.jwt = null; | |
| } | |
| } | |
| }) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment