Fixing some issues with org not being correctly detected.

This commit is contained in:
mike12345567 2021-07-27 15:35:26 +01:00
parent 1b40740709
commit 615053f201
4 changed files with 32 additions and 25 deletions

View File

@ -33,6 +33,7 @@ function finalise(ctx, { authenticated, user, internal, version } = {}) {
module.exports = (noAuthPatterns = [], opts) => { module.exports = (noAuthPatterns = [], opts) => {
const noAuthOptions = noAuthPatterns ? buildNoAuthRegex(noAuthPatterns) : [] const noAuthOptions = noAuthPatterns ? buildNoAuthRegex(noAuthPatterns) : []
return async (ctx, next) => { return async (ctx, next) => {
let publicEndpoint = false
const version = ctx.request.headers[Headers.API_VER] const version = ctx.request.headers[Headers.API_VER]
// the path is not authenticated // the path is not authenticated
const found = noAuthOptions.find(({ regex, method }) => { const found = noAuthOptions.find(({ regex, method }) => {
@ -42,7 +43,7 @@ module.exports = (noAuthPatterns = [], opts) => {
) )
}) })
if (found != null) { if (found != null) {
return next() publicEndpoint = true
} }
try { try {
// check the actual user is authenticated first // check the actual user is authenticated first
@ -93,7 +94,7 @@ module.exports = (noAuthPatterns = [], opts) => {
return next() return next()
} catch (err) { } catch (err) {
// allow configuring for public access // allow configuring for public access
if (opts && opts.publicAllowed) { if ((opts && opts.publicAllowed) || publicEndpoint) {
finalise(ctx, { authenticated: false, version }) finalise(ctx, { authenticated: false, version })
} else { } else {
ctx.throw(err.status || 403, err) ctx.throw(err.status || 403, err)

View File

@ -16,9 +16,13 @@
// Force creation of an admin user if one doesn't exist // 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) { if (loaded && multiTenancyEnabled && !tenantSet) {
$redirect("./auth/org") $redirect("./auth/org")
} else if (loaded && !hasAdminUser) { } else if (loaded && !hasAdminUser) {
$redirect("./admin") $redirect("./admin")
} }
} }

View File

@ -33,27 +33,29 @@ async function init() {
fs.writeFileSync(envoyOutputPath, processStringSync(contents, config)) fs.writeFileSync(envoyOutputPath, processStringSync(contents, config))
const envFilePath = path.join(process.cwd(), ".env") const envFilePath = path.join(process.cwd(), ".env")
const envFileJson = { if (!fs.existsSync(envFilePath)) {
PORT: 4001, const envFileJson = {
MINIO_URL: "http://localhost:10000/", PORT: 4001,
COUCH_DB_URL: "http://budibase:budibase@localhost:10000/db/", MINIO_URL: "http://localhost:10000/",
REDIS_URL: "localhost:6379", COUCH_DB_URL: "http://budibase:budibase@localhost:10000/db/",
WORKER_URL: "http://localhost:4002", REDIS_URL: "localhost:6379",
INTERNAL_API_KEY: "budibase", WORKER_URL: "http://localhost:4002",
JWT_SECRET: "testsecret", INTERNAL_API_KEY: "budibase",
REDIS_PASSWORD: "budibase", JWT_SECRET: "testsecret",
MINIO_ACCESS_KEY: "budibase", REDIS_PASSWORD: "budibase",
MINIO_SECRET_KEY: "budibase", MINIO_ACCESS_KEY: "budibase",
COUCH_DB_PASSWORD: "budibase", MINIO_SECRET_KEY: "budibase",
COUCH_DB_USER: "budibase", COUCH_DB_PASSWORD: "budibase",
SELF_HOSTED: 1, COUCH_DB_USER: "budibase",
MULTI_TENANCY: "", 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() { async function up() {

View File

@ -4,7 +4,7 @@ const {
getGlobalUserParams, getGlobalUserParams,
getScopedFullConfig, getScopedFullConfig,
getGlobalDBFromCtx, getGlobalDBFromCtx,
getGlobalDB, getTenantIdFromCtx,
getAllApps, getAllApps,
} = require("@budibase/auth/db") } = require("@budibase/auth/db")
const { Configs } = require("../../../constants") const { Configs } = require("../../../constants")
@ -218,8 +218,8 @@ exports.destroy = async function (ctx) {
} }
exports.configChecklist = async function (ctx) { exports.configChecklist = async function (ctx) {
const tenantId = ctx.request.query.tenantId const tenantId = getTenantIdFromCtx(ctx)
const db = tenantId ? getGlobalDB(tenantId) : getGlobalDBFromCtx(ctx) const db = getGlobalDBFromCtx(ctx)
try { try {
// TODO: Watch get started video // TODO: Watch get started video