diff --git a/packages/auth/src/middleware/authenticated.js b/packages/auth/src/middleware/authenticated.js index c79725233f..e3089efb1e 100644 --- a/packages/auth/src/middleware/authenticated.js +++ b/packages/auth/src/middleware/authenticated.js @@ -33,6 +33,7 @@ function finalise(ctx, { authenticated, user, internal, version } = {}) { module.exports = (noAuthPatterns = [], opts) => { const noAuthOptions = noAuthPatterns ? buildNoAuthRegex(noAuthPatterns) : [] return async (ctx, next) => { + let publicEndpoint = false const version = ctx.request.headers[Headers.API_VER] // the path is not authenticated const found = noAuthOptions.find(({ regex, method }) => { @@ -42,7 +43,7 @@ module.exports = (noAuthPatterns = [], opts) => { ) }) if (found != null) { - return next() + publicEndpoint = true } try { // check the actual user is authenticated first @@ -93,7 +94,7 @@ module.exports = (noAuthPatterns = [], opts) => { return next() } catch (err) { // allow configuring for public access - if (opts && opts.publicAllowed) { + if ((opts && opts.publicAllowed) || publicEndpoint) { finalise(ctx, { authenticated: false, version }) } else { ctx.throw(err.status || 403, err) diff --git a/packages/builder/src/pages/builder/_layout.svelte b/packages/builder/src/pages/builder/_layout.svelte index ce883ee541..6bef986f04 100644 --- a/packages/builder/src/pages/builder/_layout.svelte +++ b/packages/builder/src/pages/builder/_layout.svelte @@ -16,9 +16,13 @@ // Force creation of an admin user if one doesn't exist $: { + console.log(`loaded: ${loaded}`) + console.log(`tenancy: ${multiTenancyEnabled}`) + console.log(`tenant set: ${tenantSet}`) if (loaded && multiTenancyEnabled && !tenantSet) { $redirect("./auth/org") } else if (loaded && !hasAdminUser) { + $redirect("./admin") } } diff --git a/packages/server/scripts/dev/manage.js b/packages/server/scripts/dev/manage.js index c24d0057f0..e0801bc9df 100644 --- a/packages/server/scripts/dev/manage.js +++ b/packages/server/scripts/dev/manage.js @@ -33,27 +33,29 @@ async function init() { fs.writeFileSync(envoyOutputPath, processStringSync(contents, config)) const envFilePath = path.join(process.cwd(), ".env") - const envFileJson = { - PORT: 4001, - MINIO_URL: "http://localhost:10000/", - COUCH_DB_URL: "http://budibase:budibase@localhost:10000/db/", - REDIS_URL: "localhost:6379", - WORKER_URL: "http://localhost:4002", - INTERNAL_API_KEY: "budibase", - JWT_SECRET: "testsecret", - REDIS_PASSWORD: "budibase", - MINIO_ACCESS_KEY: "budibase", - MINIO_SECRET_KEY: "budibase", - COUCH_DB_PASSWORD: "budibase", - COUCH_DB_USER: "budibase", - SELF_HOSTED: 1, - MULTI_TENANCY: "", + if (!fs.existsSync(envFilePath)) { + const envFileJson = { + PORT: 4001, + MINIO_URL: "http://localhost:10000/", + COUCH_DB_URL: "http://budibase:budibase@localhost:10000/db/", + REDIS_URL: "localhost:6379", + WORKER_URL: "http://localhost:4002", + INTERNAL_API_KEY: "budibase", + JWT_SECRET: "testsecret", + REDIS_PASSWORD: "budibase", + MINIO_ACCESS_KEY: "budibase", + MINIO_SECRET_KEY: "budibase", + COUCH_DB_PASSWORD: "budibase", + COUCH_DB_USER: "budibase", + SELF_HOSTED: 1, + MULTI_TENANCY: "", + } + let envFile = "" + Object.keys(envFileJson).forEach(key => { + envFile += `${key}=${envFileJson[key]}\n` + }) + fs.writeFileSync(envFilePath, envFile) } - let envFile = "" - Object.keys(envFileJson).forEach(key => { - envFile += `${key}=${envFileJson[key]}\n` - }) - fs.writeFileSync(envFilePath, envFile) } async function up() { diff --git a/packages/worker/src/api/controllers/global/configs.js b/packages/worker/src/api/controllers/global/configs.js index 1eb2064b8a..ca066e1492 100644 --- a/packages/worker/src/api/controllers/global/configs.js +++ b/packages/worker/src/api/controllers/global/configs.js @@ -4,7 +4,7 @@ const { getGlobalUserParams, getScopedFullConfig, getGlobalDBFromCtx, - getGlobalDB, + getTenantIdFromCtx, getAllApps, } = require("@budibase/auth/db") const { Configs } = require("../../../constants") @@ -218,8 +218,8 @@ exports.destroy = async function (ctx) { } exports.configChecklist = async function (ctx) { - const tenantId = ctx.request.query.tenantId - const db = tenantId ? getGlobalDB(tenantId) : getGlobalDBFromCtx(ctx) + const tenantId = getTenantIdFromCtx(ctx) + const db = getGlobalDBFromCtx(ctx) try { // TODO: Watch get started video