feat: user menu + jwt certs + UI fixes
This commit is contained in:
@@ -6,6 +6,7 @@ import { make } from 'vuex-pathify' // eslint-disable-line import/no-duplicates
|
||||
|
||||
import page from './page'
|
||||
import site from './site'
|
||||
import user from './user'
|
||||
|
||||
Vue.use(Vuex)
|
||||
|
||||
@@ -51,6 +52,7 @@ export default new Vuex.Store({
|
||||
actions: { },
|
||||
modules: {
|
||||
page,
|
||||
site
|
||||
site,
|
||||
user
|
||||
}
|
||||
})
|
||||
|
44
client/store/user.js
Normal file
44
client/store/user.js
Normal file
@@ -0,0 +1,44 @@
|
||||
import { make } from 'vuex-pathify'
|
||||
import jwt from 'jsonwebtoken'
|
||||
import Cookies from 'js-cookie'
|
||||
|
||||
const state = {
|
||||
id: 0,
|
||||
email: '',
|
||||
name: '',
|
||||
pictureUrl: '',
|
||||
localeCode: '',
|
||||
defaultEditor: '',
|
||||
permissions: [],
|
||||
iat: 0,
|
||||
exp: 0,
|
||||
authenticated: false
|
||||
}
|
||||
|
||||
export default {
|
||||
namespaced: true,
|
||||
state,
|
||||
mutations: {
|
||||
...make.mutations(state),
|
||||
REFRESH_AUTH(state) {
|
||||
const jwtCookie = Cookies.get('jwt')
|
||||
if (jwtCookie) {
|
||||
try {
|
||||
const jwtData = jwt.decode(jwtCookie)
|
||||
state.id = jwtData.id
|
||||
state.email = jwtData.email
|
||||
state.name = jwtData.name
|
||||
state.pictureUrl = jwtData.pictureUrl
|
||||
state.localeCode = jwtData.localeCode
|
||||
state.defaultEditor = jwtData.defaultEditor
|
||||
state.permissions = jwtData.permissions
|
||||
state.iat = jwtData.iat
|
||||
state.exp = jwtData.exp
|
||||
state.authenticated = true
|
||||
} catch (err) {
|
||||
console.debug('Invalid JWT. Silent authentication skipped.')
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user