forked from requarks/wiki
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuser.js
50 lines (48 loc) · 1.21 KB
/
user.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import { make } from 'vuex-pathify'
import jwt from 'jsonwebtoken'
import Cookies from 'js-cookie'
const state = {
id: 0,
email: '',
name: '',
pictureUrl: '',
localeCode: '',
defaultEditor: '',
timezone: '',
dateFormat: '',
appearance: '',
permissions: [],
iat: 0,
exp: 0,
authenticated: false
}
export default {
namespaced: true,
state,
mutations: {
...make.mutations(state),
REFRESH_AUTH(st) {
const jwtCookie = Cookies.get('jwt')
if (jwtCookie) {
try {
const jwtData = jwt.decode(jwtCookie)
st.id = jwtData.id
st.email = jwtData.email
st.name = jwtData.name
st.pictureUrl = jwtData.av
st.localeCode = jwtData.lc
st.timezone = jwtData.tz || Intl.DateTimeFormat().resolvedOptions().timeZone || ''
st.dateFormat = jwtData.df || ''
st.appearance = jwtData.ap || ''
// st.defaultEditor = jwtData.defaultEditor
st.permissions = jwtData.permissions
st.iat = jwtData.iat
st.exp = jwtData.exp
st.authenticated = true
} catch (err) {
console.debug('Invalid JWT. Silent authentication skipped.')
}
}
}
}
}