budibase/packages/client/src/store/auth.js

20 lines
433 B
JavaScript
Raw Normal View History

import * as API from "../api"
import { writable } from "svelte/store"
2020-11-11 13:25:50 +01:00
const createAuthStore = () => {
const store = writable(null)
2020-11-11 13:25:50 +01:00
// 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)
}
return {
subscribe: store.subscribe,
actions: { fetchUser },
2020-11-11 13:25:50 +01:00
}
}
2020-11-11 13:25:50 +01:00
export const authStore = createAuthStore()