1
0
Fork 0
mirror of synced 2024-06-30 20:10:54 +12:00

Merge pull request #834 from Budibase/bug/more-auth-fixes

More Auth bugfixes
This commit is contained in:
Martin McKeaveney 2020-11-09 10:49:57 +00:00 committed by GitHub
commit 7db78e98ab
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 12 additions and 19 deletions

View file

@ -1,8 +1,8 @@
import { authenticate } from "./authenticate"
import { getAppId } from "../render/getAppId"
const apiCall = method => async ({ url, body }) => {
const response = await fetch(url, {
export async function baseApiCall(method, url, body) {
return await fetch(url, {
method: method,
headers: {
"Content-Type": "application/json",
@ -11,6 +11,10 @@ const apiCall = method => async ({ url, body }) => {
body: body && JSON.stringify(body),
credentials: "same-origin",
})
}
const apiCall = method => async ({ url, body }) => {
const response = await baseApiCall(method, url, body)
switch (response.status) {
case 200:

View file

@ -1,30 +1,18 @@
import setBindableComponentProp from "./setBindableComponentProp"
import { attachChildren } from "../render/attachChildren"
import store from "../state/store"
export const trimSlash = str => str.replace(/^\/+|\/+$/g, "")
import { baseApiCall } from "../api/index"
export const bbFactory = ({
componentLibraries,
onScreenSlotRendered,
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 = {
post: apiCall("POST"),
get: apiCall("GET"),
patch: apiCall("PATCH"),
delete: apiCall("DELETE"),
post: (url, body) => baseApiCall("POST", url, body),
get: (url, body) => baseApiCall("GET", url, body),
patch: (url, body) => baseApiCall("PATCH", url, body),
delete: (url, body) => baseApiCall("DELETE", url, body),
}
return (treeNode, setupState) => {

View file

@ -42,6 +42,7 @@ module.exports = async (ctx, next) => {
if (!token) {
ctx.auth.authenticated = false
ctx.appId = appId
ctx.user = {
appId,
}