Browse Source

Some updates, still WIP.

gh-pages
Michael Drury 6 years ago
parent
commit
98157f076f
  1. 2
      packages/server/src/api/controllers/application.js
  2. 2
      packages/server/src/api/controllers/auth.js
  3. 2
      packages/server/src/api/controllers/static.js
  4. 2
      packages/server/src/api/routes/tests/couchTestUtils.js
  5. 13
      packages/server/src/utilities/builder/setBuilderToken.js
  6. 4
      packages/server/src/utilities/index.js

2
packages/server/src/api/controllers/application.js

@ -61,7 +61,7 @@ exports.fetchAppPackage = async function(ctx) {
const db = new CouchDB(ctx.params.appId)
const application = await db.get(ctx.params.appId)
ctx.body = await getPackageForBuilder(ctx.config, application)
setBuilderToken(ctx, ctx.params.appId, application.version)
await setBuilderToken(ctx, ctx.params.appId, application.version)
}
exports.create = async function(ctx) {

2
packages/server/src/api/controllers/auth.js

@ -48,7 +48,7 @@ exports.authenticate = async ctx => {
const expires = new Date()
expires.setDate(expires.getDate() + 1)
ctx.cookies.set("budibase:token", token, {
ctx.cookies.set(`budibase:token`, token, {
expires,
path: "/",
httpOnly: false,

2
packages/server/src/api/controllers/static.js

@ -21,7 +21,7 @@ const COMP_LIB_BASE_APP_VERSION = "0.2.5"
exports.serveBuilder = async function(ctx) {
let builderPath = resolve(__dirname, "../../../builder")
if (ctx.file === "index.html") {
setBuilderToken(ctx)
await setBuilderToken(ctx)
}
await send(ctx, ctx.file, { root: ctx.devPath || builderPath })
}

2
packages/server/src/api/routes/tests/couchTestUtils.js

@ -209,7 +209,7 @@ const createUserWithPermissions = async (
const loginResult = await request
.post(`/api/authenticate`)
.set({ Cookie: `budibase:token=${anonToken}` })
.set({ Cookie: `budibase:${appId}=${anonToken}` })
.send({ username, password })
// returning necessary request headers

13
packages/server/src/utilities/builder/setBuilderToken.js

@ -1,8 +1,9 @@
const { BUILDER_LEVEL_ID } = require("../accessLevels")
const env = require("../../environment")
const CouchDB = require("../../db")
const jwt = require("jsonwebtoken")
module.exports = (ctx, appId, version) => {
module.exports = async (ctx, appId, version) => {
const builderUser = {
userId: "BUILDER",
accessLevelId: BUILDER_LEVEL_ID,
@ -18,14 +19,16 @@ module.exports = (ctx, appId, version) => {
const expiry = new Date()
expiry.setDate(expiry.getDate() + 30)
// remove the app token
ctx.cookies.set("budibase:token", "", {
overwrite: true,
})
// set the builder token
ctx.cookies.set("builder:token", token, {
expires: expiry,
httpOnly: false,
overwrite: true,
})
// need to clear all app tokens or else unable to use the app in the builder
let allDbNames = await CouchDB.allDbs()
allDbNames.map(dbName => {})
ctx.cookies.set(`budibase:${appId}`, "", {
overwrite: true,
})
}

4
packages/server/src/utilities/index.js

@ -10,3 +10,7 @@ exports.isDev = () => {
env.NODE_ENV !== "cypress"
)
}
exports.getAppId = ctx => {
}

Loading…
Cancel
Save