frontend/src/store.js
Philipp Dormann 5b15141ecc
All checks were successful
continuous-integration/drone/push Build is passing
general cleanups
2021-01-04 19:39:57 +01:00

46 lines
771 B
JavaScript

import { writable } from 'svelte/store';
export let tracks = writable([]);
const store = () => {
const state = {
access_token: undefined,
jwtinfo: undefined,
isLoggedIn: false
};
const { subscribe, set, update } = writable(state);
const methods = {
init() {
update((state) => {
state.isLoggedIn = false;
return state;
});
},
login(access_token, jwtinfo) {
update((state) => {
state.access_token = access_token;
state.jwtinfo = jwtinfo;
state.isLoggedIn = true;
// console.log('login performed');
return state;
});
},
logout() {
update((state) => {
state.isLoggedIn = false;
return state;
});
}
};
return {
subscribe,
set,
update,
state,
...methods
};
};
export default store();