|
|
|
@ -1,18 +1,29 @@ |
|
|
|
import * as API from "../api" |
|
|
|
import { getAppId } from "../utils/getAppId" |
|
|
|
import { writable } from "svelte/store" |
|
|
|
import { initialise } from "./initialise" |
|
|
|
import { routeStore } from "./routes" |
|
|
|
|
|
|
|
const createAuthStore = () => { |
|
|
|
const store = writable("") |
|
|
|
|
|
|
|
const goToDefaultRoute = () => { |
|
|
|
// Setting the active route forces an update of the active screen ID,
|
|
|
|
// even if we're on the same URL
|
|
|
|
routeStore.actions.setActiveRoute("/") |
|
|
|
|
|
|
|
// Navigating updates the URL to reflect this route
|
|
|
|
routeStore.actions.navigate("/") |
|
|
|
} |
|
|
|
const logIn = async ({ email, password }) => { |
|
|
|
const user = await API.logIn({ email, password }) |
|
|
|
if (!user.error) { |
|
|
|
store.set(user.token) |
|
|
|
location.reload() |
|
|
|
await initialise() |
|
|
|
goToDefaultRoute() |
|
|
|
} |
|
|
|
} |
|
|
|
const logOut = () => { |
|
|
|
const logOut = async () => { |
|
|
|
store.set("") |
|
|
|
const appId = getAppId() |
|
|
|
if (appId) { |
|
|
|
@ -20,7 +31,8 @@ const createAuthStore = () => { |
|
|
|
window.document.cookie = `budibase:${appId}:${environment}=; Path=/; Expires=Thu, 01 Jan 1970 00:00:01 GMT;` |
|
|
|
} |
|
|
|
} |
|
|
|
location.reload() |
|
|
|
await initialise() |
|
|
|
goToDefaultRoute() |
|
|
|
} |
|
|
|
|
|
|
|
return { |
|
|
|
|