Plan stuff. Log stuff.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

49 lines
1.0 KiB

import { writable } from "svelte/store";
import slApi from "../api/stufflog";
import stufflogStore from "./stufflog";
function createAuthStore() {
const {set, update, subscribe} = writable({checked: false, user: null})
return {
subscribe,
async check() {
const data = await slApi.checkSession();
set({checked: true, user: data.user || null});
return data;
},
async login(username, password) {
const data = await slApi.login(username, password);
set({checked: true, user: data.user});
return data;
},
async logout() {
const data = await slApi.logout();
stufflogStore.clearAll();
set({checked: true, user: data.user || null});
return data;
},
async register(username, password) {
const data = await slApi.register(username, password);
stufflogStore.clearAll();
set({checked: true, user: data.user});
return data;
},
}
}
const session = createAuthStore();
export default session;