1
0
Fork 0
mirror of synced 2024-10-06 13:04:36 +13:00
budibase/packages/client/src/store/auth.js

24 lines
637 B
JavaScript

import * as API from "../api"
import { writable } from "svelte/store"
const createAuthStore = () => {
const store = writable(null)
// Fetches the user object if someone is logged in and has reloaded the page
const fetchUser = async () => {
const user = await API.fetchSelf()
store.set(user)
}
const logOut = async () => {
window.document.cookie = `budibase:auth=; budibase:currentapp=; Path=/; Expires=Thu, 01 Jan 1970 00:00:01 GMT;`
window.location = "/builder/auth/login"
}
return {
subscribe: store.subscribe,
actions: { fetchUser, logOut },
}
}
export const authStore = createAuthStore()