2020-03-02 23:15:44 +01:00
|
|
|
import { writable } from 'svelte/store';
|
2020-04-10 05:02:19 +02:00
|
|
|
import * as api from './api';
|
2019-07-26 23:05:29 +02:00
|
|
|
|
|
|
|
const { subscribe, set } = writable<boolean>(false);
|
|
|
|
|
|
|
|
export const loggedIn = {
|
|
|
|
subscribe,
|
|
|
|
fetchIsLoggedIn(): Promise<void> {
|
|
|
|
return api.isLoggedIn().then((isLoggedIn: boolean) => {
|
|
|
|
set(isLoggedIn);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
fetchLogin(credentials: ICredentials): Promise<void> {
|
2019-12-15 01:14:39 +01:00
|
|
|
return api.login(credentials).then(this.fetchIsLoggedIn);
|
2019-07-26 23:05:29 +02:00
|
|
|
},
|
|
|
|
};
|