Use the real current user even inside builder preview
This commit is contained in:
parent
2aa829b782
commit
0fb12e7619
|
@ -1,26 +1,13 @@
|
||||||
import * as API from "../api"
|
import * as API from "../api"
|
||||||
import { writable, get } from "svelte/store"
|
import { writable } from "svelte/store"
|
||||||
import { builderStore } from "./builder"
|
|
||||||
import { TableNames } from "../constants"
|
|
||||||
|
|
||||||
const createAuthStore = () => {
|
const createAuthStore = () => {
|
||||||
const store = writable(null)
|
const store = writable(null)
|
||||||
|
|
||||||
// Fetches the user object if someone is logged in and has reloaded the page
|
// Fetches the user object if someone is logged in and has reloaded the page
|
||||||
const fetchUser = async () => {
|
const fetchUser = async () => {
|
||||||
// Fetch the first user if inside the builder
|
const user = await API.fetchSelf()
|
||||||
if (get(builderStore).inBuilder) {
|
store.set(user)
|
||||||
const users = await API.fetchTableData(TableNames.USERS)
|
|
||||||
if (!users.error && users[0] != null) {
|
|
||||||
store.set(users[0])
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Or fetch the current user from localstorage in a real app
|
|
||||||
else {
|
|
||||||
const user = await API.fetchSelf()
|
|
||||||
store.set(user)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|
Loading…
Reference in New Issue