This repository has been archived on 2024-07-22. You can view files and clone it, but cannot push or open issues or pull requests.
Zaimki/store/index.js

55 lines
1.2 KiB
JavaScript
Raw Normal View History

import jwt from 'jsonwebtoken';
export const state = () => ({
token: null,
user: null,
2021-12-18 10:54:36 -08:00
preToken: null,
spelling: 'traditional',
2021-10-26 11:13:42 -07:00
darkMode: false,
})
export const mutations = {
setToken(state, token) {
if (!token) {
state.token = null;
state.user = null;
return;
}
let user;
try {
user = jwt.verify(token, process.env.PUBLIC_KEY, {
algorithm: 'RS256',
audience: process.env.ALL_LOCALES_URLS.split(','),
issuer: process.env.ALL_LOCALES_URLS.split(','),
});
} catch (e) {
console.error(e);
user = null;
}
2021-12-18 10:54:36 -08:00
if (user && user.mfaRequired) {
state.preToken = token;
}
if (user && user.authenticated) {
2021-12-18 10:54:36 -08:00
state.preToken = null;
state.token = token;
state.user = user;
return;
}
state.token = null;
state.user = null;
},
2021-12-18 10:54:36 -08:00
cancelMfa(state) {
state.preToken = null;
},
setSpelling(state, spelling) {
state.spelling = spelling;
},
2021-10-26 11:13:42 -07:00
setDarkMode(state, isDark) {
state.darkMode = isDark;
}
}