mirror of
https://github.com/kevin-DL/sapper-template.git
synced 2026-01-12 10:25:16 +00:00
28 lines
781 B
JavaScript
28 lines
781 B
JavaScript
import { init } from 'sapper/runtime.js';
|
|
import { manifest } from './manifest/client.js';
|
|
import { Store } from 'svelte/store.js'
|
|
|
|
init({
|
|
target: document.querySelector('#sapper'),
|
|
manifest,
|
|
store: data => {
|
|
const user = data.user;
|
|
const store = new Store(data);
|
|
if (!user) {
|
|
// SEE: https://stackoverflow.com/questions/10593013/delete-cookie-by-name
|
|
document.cookie = 'ds=;expires=Sun, 09 Jan 1974 00:00:01 GMT;';
|
|
}
|
|
store.set({
|
|
logout: () => {
|
|
return fetch('auth/logout', { method: 'POST' }).then(() => {
|
|
// SEE: https://stackoverflow.com/questions/10593013/delete-cookie-by-name
|
|
document.cookie = 'ds=;expires=Sun, 09 Jan 1974 00:00:01 GMT;';
|
|
store.set({ user: null });
|
|
window.location = '/'
|
|
})
|
|
},
|
|
})
|
|
return store
|
|
}
|
|
});
|