1
0
Fork 0
mirror of synced 2024-10-01 17:47:46 +13:00

Adding back logout functionality.

This commit is contained in:
Michael Drury 2021-07-25 12:07:25 +01:00
parent ef3ee02885
commit 48f797185c
2 changed files with 25 additions and 2 deletions

View file

@ -1,18 +1,36 @@
import * as API from "../api"
import { writable } from "svelte/store"
import { initialise } from "./initialise"
const createAuthStore = () => {
const store = writable(null)
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("/")
}
// 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 () => {
store.set(null)
window.document.cookie = `budibase:auth=; budibase:currentapp=; Path=/; Expires=Thu, 01 Jan 1970 00:00:01 GMT;`
await initialise()
goToDefaultRoute()
}
return {
subscribe: store.subscribe,
actions: { fetchUser },
actions: { fetchUser, logOut },
}
}

View file

@ -1,5 +1,5 @@
import { get } from "svelte/store"
import { routeStore, builderStore, confirmationStore } from "../store"
import { routeStore, builderStore, confirmationStore, authStore } from "../store"
import { saveRow, deleteRow, executeQuery, triggerAutomation } from "../api"
import { ActionTypes } from "../constants"
@ -77,6 +77,10 @@ const refreshDatasourceHandler = async (action, context) => {
)
}
const logoutHandler = async () => {
await authStore.actions.logOut()
}
const handlerMap = {
["Save Row"]: saveRowHandler,
["Delete Row"]: deleteRowHandler,
@ -85,6 +89,7 @@ const handlerMap = {
["Trigger Automation"]: triggerAutomationHandler,
["Validate Form"]: validateFormHandler,
["Refresh Datasource"]: refreshDatasourceHandler,
["Log Out"]: logoutHandler,
}
const confirmTextMap = {