Merge pull request #834 from Budibase/bug/more-auth-fixes
More Auth bugfixes
This commit is contained in:
commit
b102559aff
|
@ -1,8 +1,8 @@
|
||||||
import { authenticate } from "./authenticate"
|
import { authenticate } from "./authenticate"
|
||||||
import { getAppId } from "../render/getAppId"
|
import { getAppId } from "../render/getAppId"
|
||||||
|
|
||||||
const apiCall = method => async ({ url, body }) => {
|
export async function baseApiCall(method, url, body) {
|
||||||
const response = await fetch(url, {
|
return await fetch(url, {
|
||||||
method: method,
|
method: method,
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
|
@ -11,6 +11,10 @@ const apiCall = method => async ({ url, body }) => {
|
||||||
body: body && JSON.stringify(body),
|
body: body && JSON.stringify(body),
|
||||||
credentials: "same-origin",
|
credentials: "same-origin",
|
||||||
})
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
const apiCall = method => async ({ url, body }) => {
|
||||||
|
const response = await baseApiCall(method, url, body)
|
||||||
|
|
||||||
switch (response.status) {
|
switch (response.status) {
|
||||||
case 200:
|
case 200:
|
||||||
|
|
|
@ -1,30 +1,18 @@
|
||||||
import setBindableComponentProp from "./setBindableComponentProp"
|
import setBindableComponentProp from "./setBindableComponentProp"
|
||||||
import { attachChildren } from "../render/attachChildren"
|
import { attachChildren } from "../render/attachChildren"
|
||||||
import store from "../state/store"
|
import store from "../state/store"
|
||||||
|
import { baseApiCall } from "../api/index"
|
||||||
export const trimSlash = str => str.replace(/^\/+|\/+$/g, "")
|
|
||||||
|
|
||||||
export const bbFactory = ({
|
export const bbFactory = ({
|
||||||
componentLibraries,
|
componentLibraries,
|
||||||
onScreenSlotRendered,
|
onScreenSlotRendered,
|
||||||
runEventActions,
|
runEventActions,
|
||||||
}) => {
|
}) => {
|
||||||
const apiCall = method => (url, body) => {
|
|
||||||
return fetch(url, {
|
|
||||||
method: method,
|
|
||||||
headers: {
|
|
||||||
"Content-Type": "application/json",
|
|
||||||
},
|
|
||||||
body: body && JSON.stringify(body),
|
|
||||||
credentials: "same-origin",
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
const api = {
|
const api = {
|
||||||
post: apiCall("POST"),
|
post: (url, body) => baseApiCall("POST", url, body),
|
||||||
get: apiCall("GET"),
|
get: (url, body) => baseApiCall("GET", url, body),
|
||||||
patch: apiCall("PATCH"),
|
patch: (url, body) => baseApiCall("PATCH", url, body),
|
||||||
delete: apiCall("DELETE"),
|
delete: (url, body) => baseApiCall("DELETE", url, body),
|
||||||
}
|
}
|
||||||
|
|
||||||
return (treeNode, setupState) => {
|
return (treeNode, setupState) => {
|
||||||
|
|
|
@ -42,6 +42,7 @@ module.exports = async (ctx, next) => {
|
||||||
|
|
||||||
if (!token) {
|
if (!token) {
|
||||||
ctx.auth.authenticated = false
|
ctx.auth.authenticated = false
|
||||||
|
ctx.appId = appId
|
||||||
ctx.user = {
|
ctx.user = {
|
||||||
appId,
|
appId,
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue