A lot of general fixes around getting logged in, setting up users etc.
This commit is contained in:
parent
99fe16d169
commit
07dd7d68d4
|
@ -4,7 +4,9 @@
|
||||||
import { onMount } from "svelte"
|
import { onMount } from "svelte"
|
||||||
|
|
||||||
let loaded = false
|
let loaded = false
|
||||||
|
$: multiTenancyEnabled = $admin.multiTenancy
|
||||||
$: hasAdminUser = !!$admin?.checklist?.adminUser
|
$: hasAdminUser = !!$admin?.checklist?.adminUser
|
||||||
|
$: tenantSet = $auth.tenantSet
|
||||||
|
|
||||||
onMount(async () => {
|
onMount(async () => {
|
||||||
await admin.init()
|
await admin.init()
|
||||||
|
@ -14,7 +16,9 @@
|
||||||
|
|
||||||
// Force creation of an admin user if one doesn't exist
|
// Force creation of an admin user if one doesn't exist
|
||||||
$: {
|
$: {
|
||||||
if (loaded && !hasAdminUser) {
|
if (loaded && multiTenancyEnabled && !tenantSet) {
|
||||||
|
$redirect("./auth/org")
|
||||||
|
} else if (loaded && !hasAdminUser) {
|
||||||
$redirect("./admin")
|
$redirect("./admin")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,15 +9,18 @@
|
||||||
} from "@budibase/bbui"
|
} from "@budibase/bbui"
|
||||||
import { goto } from "@roxi/routify"
|
import { goto } from "@roxi/routify"
|
||||||
import api from "builderStore/api"
|
import api from "builderStore/api"
|
||||||
import { admin } from "stores/portal"
|
import { admin, auth } from "stores/portal"
|
||||||
import PasswordRepeatInput from "components/common/users/PasswordRepeatInput.svelte"
|
import PasswordRepeatInput from "components/common/users/PasswordRepeatInput.svelte"
|
||||||
import Logo from "assets/bb-emblem.svg"
|
import Logo from "assets/bb-emblem.svg"
|
||||||
|
|
||||||
let adminUser = {}
|
let adminUser = {}
|
||||||
let error
|
let error
|
||||||
|
|
||||||
|
$: tenantId = $auth.tenantId
|
||||||
|
|
||||||
async function save() {
|
async function save() {
|
||||||
try {
|
try {
|
||||||
|
adminUser.tenantId = tenantId
|
||||||
// Save the admin user
|
// Save the admin user
|
||||||
const response = await api.post(`/api/admin/users/init`, adminUser)
|
const response = await api.post(`/api/admin/users/init`, adminUser)
|
||||||
const json = await response.json()
|
const json = await response.json()
|
||||||
|
@ -44,7 +47,6 @@
|
||||||
</Body>
|
</Body>
|
||||||
</Layout>
|
</Layout>
|
||||||
<Layout gap="XS" noPadding>
|
<Layout gap="XS" noPadding>
|
||||||
<Input label="Organisation" bind:value={adminUser.tenantId} />
|
|
||||||
<Input label="Email" bind:value={adminUser.email} />
|
<Input label="Email" bind:value={adminUser.email} />
|
||||||
<PasswordRepeatInput bind:password={adminUser.password} bind:error />
|
<PasswordRepeatInput bind:password={adminUser.password} bind:error />
|
||||||
</Layout>
|
</Layout>
|
||||||
|
|
|
@ -1,5 +1,24 @@
|
||||||
<script>
|
<script>
|
||||||
import { redirect } from "@roxi/routify"
|
import { redirect } from "@roxi/routify"
|
||||||
// TODO: need to check if the tenant is already set
|
import { auth, admin } from "stores/portal"
|
||||||
|
import { onMount } from "svelte"
|
||||||
|
|
||||||
|
$: tenantSet = $auth.tenantSet
|
||||||
|
$: multiTenancyEnabled = $admin.multiTenancy
|
||||||
|
|
||||||
|
let loaded = false
|
||||||
|
|
||||||
|
$: {
|
||||||
|
console.log(loaded)
|
||||||
|
if (loaded && multiTenancyEnabled && !tenantSet) {
|
||||||
$redirect("./org")
|
$redirect("./org")
|
||||||
|
} else if (loaded) {
|
||||||
|
$redirect("./login")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
onMount(async () => {
|
||||||
|
await admin.init()
|
||||||
|
loaded = true
|
||||||
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|
|
@ -1,14 +1,16 @@
|
||||||
<script>
|
<script>
|
||||||
import { Body, Button, Divider, Heading, Input, Layout } from "@budibase/bbui"
|
import { Body, Button, Divider, Heading, Input, Layout } from "@budibase/bbui"
|
||||||
import { goto } from "@roxi/routify"
|
import { goto } from "@roxi/routify"
|
||||||
import { auth } from "stores/portal"
|
import { auth, admin } from "stores/portal"
|
||||||
import Logo from "assets/bb-emblem.svg"
|
import Logo from "assets/bb-emblem.svg"
|
||||||
|
|
||||||
let tenantId = ""
|
let tenantId = ""
|
||||||
|
|
||||||
async function setOrg() {
|
async function setOrg() {
|
||||||
auth.setOrg(tenantId)
|
auth.setOrg(tenantId)
|
||||||
$goto("./login")
|
// re-init now org selected
|
||||||
|
await admin.init()
|
||||||
|
$goto("../")
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleKeydown(evt) {
|
function handleKeydown(evt) {
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
|
|
||||||
$: {
|
$: {
|
||||||
if (!$auth.user) {
|
if (!$auth.user) {
|
||||||
$redirect("./auth/login")
|
$redirect("./auth")
|
||||||
} else if ($auth.user.builder?.global) {
|
} else if ($auth.user.builder?.global) {
|
||||||
$redirect("./portal")
|
$redirect("./portal")
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -90,12 +90,15 @@
|
||||||
}
|
}
|
||||||
loading = false
|
loading = false
|
||||||
requireAuth = smtpConfig.config.auth != null
|
requireAuth = smtpConfig.config.auth != null
|
||||||
|
console.log(requireAuth)
|
||||||
// always attach the auth for the forms purpose -
|
// always attach the auth for the forms purpose -
|
||||||
// this will be removed later if required
|
// this will be removed later if required
|
||||||
|
if (!smtpDoc.config.auth) {
|
||||||
smtpConfig.config.auth = {
|
smtpConfig.config.auth = {
|
||||||
type: "login",
|
type: "login",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fetchSmtp()
|
fetchSmtp()
|
||||||
</script>
|
</script>
|
||||||
|
|
|
@ -3,7 +3,7 @@ import api from "builderStore/api"
|
||||||
import { auth } from "stores/portal"
|
import { auth } from "stores/portal"
|
||||||
|
|
||||||
export function createAdminStore() {
|
export function createAdminStore() {
|
||||||
const { subscribe, set } = writable({})
|
const admin = writable({})
|
||||||
|
|
||||||
async function init() {
|
async function init() {
|
||||||
try {
|
try {
|
||||||
|
@ -20,19 +20,38 @@ export function createAdminStore() {
|
||||||
0
|
0
|
||||||
)
|
)
|
||||||
|
|
||||||
set({
|
admin.update(store => {
|
||||||
checklist: json,
|
store.checklist = json
|
||||||
onboardingProgress: (stepsComplete / onboardingSteps.length) * 100,
|
store.onboardingProgress = (stepsComplete / onboardingSteps.length) * 100
|
||||||
|
return store
|
||||||
})
|
})
|
||||||
|
await multiTenancyEnabled()
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
set({
|
admin.update( store => {
|
||||||
checklist: null,
|
store.checklist = null
|
||||||
|
return store
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function multiTenancyEnabled() {
|
||||||
|
let enabled = false
|
||||||
|
try {
|
||||||
|
const response = await api.get(`/api/admin/tenants/enabled`)
|
||||||
|
const json = await response.json()
|
||||||
|
enabled = json.enabled
|
||||||
|
} catch (err) {
|
||||||
|
// just let it stay disabled
|
||||||
|
}
|
||||||
|
admin.update(store => {
|
||||||
|
store.multiTenancy = enabled
|
||||||
|
return store
|
||||||
|
})
|
||||||
|
return enabled
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
subscribe,
|
subscribe: admin.subscribe,
|
||||||
init,
|
init,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,6 +5,7 @@ export function createAuthStore() {
|
||||||
const auth = writable({
|
const auth = writable({
|
||||||
user: null,
|
user: null,
|
||||||
tenantId: "default",
|
tenantId: "default",
|
||||||
|
tenantSet: false,
|
||||||
})
|
})
|
||||||
const store = derived(auth, $store => {
|
const store = derived(auth, $store => {
|
||||||
let initials = null
|
let initials = null
|
||||||
|
@ -28,6 +29,7 @@ export function createAuthStore() {
|
||||||
return {
|
return {
|
||||||
user: $store.user,
|
user: $store.user,
|
||||||
tenantId: $store.tenantId,
|
tenantId: $store.tenantId,
|
||||||
|
tenantSet: $store.tenantSet,
|
||||||
initials,
|
initials,
|
||||||
isAdmin,
|
isAdmin,
|
||||||
isBuilder,
|
isBuilder,
|
||||||
|
@ -46,6 +48,7 @@ export function createAuthStore() {
|
||||||
setOrg: tenantId => {
|
setOrg: tenantId => {
|
||||||
auth.update(store => {
|
auth.update(store => {
|
||||||
store.tenantId = tenantId
|
store.tenantId = tenantId
|
||||||
|
store.tenantSet = true
|
||||||
return store
|
return store
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
|
|
@ -12,12 +12,11 @@ async function init() {
|
||||||
INTERNAL_API_KEY: "budibase",
|
INTERNAL_API_KEY: "budibase",
|
||||||
MINIO_ACCESS_KEY: "budibase",
|
MINIO_ACCESS_KEY: "budibase",
|
||||||
MINIO_SECRET_KEY: "budibase",
|
MINIO_SECRET_KEY: "budibase",
|
||||||
COUCH_DB_USER: "budibase",
|
|
||||||
COUCH_DB_PASSWORD: "budibase",
|
|
||||||
REDIS_URL: "localhost:6379",
|
REDIS_URL: "localhost:6379",
|
||||||
REDIS_PASSWORD: "budibase",
|
REDIS_PASSWORD: "budibase",
|
||||||
MINIO_URL: "http://localhost:10000/",
|
MINIO_URL: "http://localhost:10000/",
|
||||||
COUCH_DB_URL: "http://budibase:budibase@localhost:10000/db/",
|
COUCH_DB_URL: "http://budibase:budibase@localhost:10000/db/",
|
||||||
|
MULTI_TENANCY: false,
|
||||||
}
|
}
|
||||||
let envFile = ""
|
let envFile = ""
|
||||||
Object.keys(envFileJson).forEach(key => {
|
Object.keys(envFileJson).forEach(key => {
|
||||||
|
|
|
@ -1,5 +1,9 @@
|
||||||
exports.multiTenancyEnabled = async ctx => {
|
const env = require("../../../environment")
|
||||||
|
|
||||||
|
exports.multiTenancyEnabled = async ctx => {
|
||||||
|
ctx.body = {
|
||||||
|
enabled: !!env.MULTI_TENANCY,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.exists = async ctx => {
|
exports.exists = async ctx => {
|
||||||
|
|
|
@ -41,6 +41,10 @@ const PUBLIC_ENDPOINTS = [
|
||||||
route: "/api/admin/configs/public",
|
route: "/api/admin/configs/public",
|
||||||
method: "GET",
|
method: "GET",
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
route: "api/admin/tenants/enabled",
|
||||||
|
method: "GET",
|
||||||
|
}
|
||||||
]
|
]
|
||||||
|
|
||||||
const router = new Router()
|
const router = new Router()
|
||||||
|
|
|
@ -1,8 +1,5 @@
|
||||||
const Router = require("@koa/router")
|
const Router = require("@koa/router")
|
||||||
const controller = require("../../controllers/admin/tenants")
|
const controller = require("../../controllers/admin/tenants")
|
||||||
const joiValidator = require("../../../middleware/joi-validator")
|
|
||||||
const Joi = require("joi")
|
|
||||||
const { TemplatePurpose, TemplateTypes } = require("../../../constants")
|
|
||||||
const adminOnly = require("../../../middleware/adminOnly")
|
const adminOnly = require("../../../middleware/adminOnly")
|
||||||
|
|
||||||
const router = Router()
|
const router = Router()
|
||||||
|
|
|
@ -2,6 +2,7 @@ const userRoutes = require("./admin/users")
|
||||||
const configRoutes = require("./admin/configs")
|
const configRoutes = require("./admin/configs")
|
||||||
const workspaceRoutes = require("./admin/workspaces")
|
const workspaceRoutes = require("./admin/workspaces")
|
||||||
const templateRoutes = require("./admin/templates")
|
const templateRoutes = require("./admin/templates")
|
||||||
|
const tenantsRoutes = require("./admin/tenants")
|
||||||
const emailRoutes = require("./admin/email")
|
const emailRoutes = require("./admin/email")
|
||||||
const authRoutes = require("./admin/auth")
|
const authRoutes = require("./admin/auth")
|
||||||
const roleRoutes = require("./admin/roles")
|
const roleRoutes = require("./admin/roles")
|
||||||
|
@ -15,6 +16,7 @@ exports.routes = [
|
||||||
authRoutes,
|
authRoutes,
|
||||||
appRoutes,
|
appRoutes,
|
||||||
templateRoutes,
|
templateRoutes,
|
||||||
|
tenantsRoutes,
|
||||||
emailRoutes,
|
emailRoutes,
|
||||||
sessionRoutes,
|
sessionRoutes,
|
||||||
roleRoutes,
|
roleRoutes,
|
||||||
|
|
|
@ -30,9 +30,7 @@ module.exports = {
|
||||||
REDIS_URL: process.env.REDIS_URL,
|
REDIS_URL: process.env.REDIS_URL,
|
||||||
REDIS_PASSWORD: process.env.REDIS_PASSWORD,
|
REDIS_PASSWORD: process.env.REDIS_PASSWORD,
|
||||||
INTERNAL_API_KEY: process.env.INTERNAL_API_KEY,
|
INTERNAL_API_KEY: process.env.INTERNAL_API_KEY,
|
||||||
/* TODO: to remove - once deployment removed */
|
MULTI_TENANCY: process.env.MULTI_TENANCY,
|
||||||
COUCH_DB_USERNAME: process.env.COUCH_DB_USERNAME,
|
|
||||||
COUCH_DB_PASSWORD: process.env.COUCH_DB_PASSWORD,
|
|
||||||
_set(key, value) {
|
_set(key, value) {
|
||||||
process.env[key] = value
|
process.env[key] = value
|
||||||
module.exports[key] = value
|
module.exports[key] = value
|
||||||
|
|
Loading…
Reference in New Issue