frontend/src/store.js
Philipp Dormann 59d5ad5bd3
All checks were successful
continuous-integration/drone/push Build is passing
logic cleanup 🧠
ref #12
2021-01-09 16:06:03 +01:00

46 lines
765 B
JavaScript

import { writable } from 'svelte/store';
export let users = writable([]);
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;
return state;
});
},
logout() {
update((state) => {
state.isLoggedIn = false;
return state;
});
}
};
return {
subscribe,
set,
update,
state,
...methods
};
};
export default store();