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.
2020-10-15 09:50:32 -07:00
|
|
|
import jwt from 'jsonwebtoken';
|
|
|
|
|
|
|
|
export const state = () => ({
|
|
|
|
token: null,
|
|
|
|
user: null,
|
|
|
|
})
|
|
|
|
|
|
|
|
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',
|
|
|
|
audience: process.env.BASE_URL,
|
|
|
|
issuer: process.env.BASE_URL,
|
|
|
|
});
|
|
|
|
} catch {
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|