+Vuex +ElementUI +Pug
- Log on now works, storing user profile in vuex state - Templates in Pug = awesome
This commit is contained in:
31
src/app/src/store/index.js
Normal file
31
src/app/src/store/index.js
Normal file
@@ -0,0 +1,31 @@
|
||||
import Vue from 'vue'
|
||||
import Vuex from 'vuex'
|
||||
|
||||
import AuthService from '@/auth/AuthService'
|
||||
|
||||
import * as types from './mutation-types'
|
||||
|
||||
Vue.use(Vuex)
|
||||
|
||||
this.auth0 = new AuthService()
|
||||
|
||||
export default new Vuex.Store({
|
||||
state: {
|
||||
user: JSON.parse(localStorage.getItem('user_profile') || '{}'),
|
||||
isAuthenticated: this.auth0.isAuthenticated()
|
||||
},
|
||||
mutations: {
|
||||
[types.USER_LOGGED_ON] (state, user) {
|
||||
localStorage.setItem('user_profile', JSON.stringify(user))
|
||||
state.user = user
|
||||
state.isAuthenticated = true
|
||||
},
|
||||
[types.USER_LOGGED_OFF] (state) {
|
||||
state.user = {}
|
||||
state.isAuthenticated = false
|
||||
}
|
||||
},
|
||||
actions: {},
|
||||
getters: {},
|
||||
modules: {}
|
||||
})
|
||||
2
src/app/src/store/mutation-types.js
Normal file
2
src/app/src/store/mutation-types.js
Normal file
@@ -0,0 +1,2 @@
|
||||
export const USER_LOGGED_OFF = 'user-logged-out'
|
||||
export const USER_LOGGED_ON = 'user-logged-on'
|
||||
Reference in New Issue
Block a user