2020-10-15 09:50:32 -07:00
|
|
|
import jwt from 'jsonwebtoken';
|
|
|
|
|
|
|
|
export const state = () => ({
|
|
|
|
token: null,
|
|
|
|
user: null,
|
2020-12-27 08:52:21 -08:00
|
|
|
spelling: 'traditional',
|
2021-10-26 11:13:42 -07:00
|
|
|
darkMode: false,
|
2020-10-15 09:50:32 -07:00
|
|
|
})
|
|
|
|
|
|
|
|
export const mutations = {
|
|
|
|
setToken(state, token) {
|
|
|
|
if (!token) {
|
|
|
|
state.token = null;
|
|
|
|
state.user = null;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-10-15 10:23:53 -07:00
|
|
|
let user;
|
|
|
|
try {
|
|
|
|
user = jwt.verify(token, process.env.PUBLIC_KEY, {
|
|
|
|
algorithm: 'RS256',
|
2021-08-22 14:53:22 -07:00
|
|
|
audience: process.env.ALL_LOCALES_URLS.split(','),
|
|
|
|
issuer: process.env.ALL_LOCALES_URLS.split(','),
|
2020-10-15 10:23:53 -07:00
|
|
|
});
|
2021-08-22 14:53:22 -07:00
|
|
|
} catch (e) {
|
|
|
|
console.error(e);
|
2020-10-15 10:23:53 -07:00
|
|
|
user = null;
|
|
|
|
}
|
2020-10-15 09:50:32 -07:00
|
|
|
|
|
|
|
if (user && user.authenticated) {
|
|
|
|
state.token = token;
|
|
|
|
state.user = user;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
state.token = null;
|
|
|
|
state.user = null;
|
2020-12-27 08:52:21 -08:00
|
|
|
},
|
|
|
|
setSpelling(state, spelling) {
|
|
|
|
state.spelling = spelling;
|
|
|
|
},
|
2021-10-26 11:13:42 -07:00
|
|
|
setDarkMode(state, isDark) {
|
|
|
|
state.darkMode = isDark;
|
|
|
|
}
|
2020-10-15 09:50:32 -07:00
|
|
|
}
|