mirror of
https://github.com/n8n-io/self-hosted-ai-starter-kit.git
synced 2025-11-29 00:23:13 +00:00
disable UM, and use the instance owner for everything
This commit is contained in:
@@ -43,12 +43,14 @@ services:
|
||||
- N8N_PERSONALIZATION_ENABLED=false
|
||||
- N8N_ENCRYPTION_KEY
|
||||
- N8N_USER_MANAGEMENT_JWT_SECRET
|
||||
- EXTERNAL_HOOK_FILES=/hooks.js
|
||||
ports:
|
||||
- 5678:5678
|
||||
links:
|
||||
- postgres
|
||||
volumes:
|
||||
- n8n_storage:/home/node/.n8n
|
||||
- ./n8n/hooks.js:/hooks.js
|
||||
depends_on:
|
||||
postgres:
|
||||
condition: service_healthy
|
||||
|
||||
54
n8n/hooks.js
Normal file
54
n8n/hooks.js
Normal file
@@ -0,0 +1,54 @@
|
||||
/**
|
||||
* A hook that disables the user management and uses owner for all requests
|
||||
*/
|
||||
const { dirname, resolve } = require("path");
|
||||
const Layer = require("express/lib/router/layer");
|
||||
|
||||
const n8nDir = dirname(require.resolve("n8n"));
|
||||
const jwtAuth = require(resolve(n8nDir, "auth/jwt"));
|
||||
|
||||
async function disableUmHook({ app }, config) {
|
||||
await this.dbCollections.Settings.update(
|
||||
{ key: "userManagement.isInstanceOwnerSetUp" },
|
||||
{ value: JSON.stringify(true) }
|
||||
);
|
||||
|
||||
config.set("userManagement.isInstanceOwnerSetUp", true);
|
||||
|
||||
const owner = await this.dbCollections.User.findOne({
|
||||
where: { role: "global:owner" },
|
||||
});
|
||||
|
||||
owner.email = "demo@n8n.io";
|
||||
owner.firstName = "Demo";
|
||||
owner.lastName = "McDemoFace";
|
||||
|
||||
await this.dbCollections.User.save(owner);
|
||||
|
||||
jwtAuth.resolveJwt = () => owner;
|
||||
|
||||
const { stack } = app._router;
|
||||
const index = stack.findIndex((l) => l.name === "cookieParser");
|
||||
stack.splice(
|
||||
index + 4,
|
||||
3,
|
||||
new Layer(
|
||||
"/",
|
||||
{
|
||||
strict: false,
|
||||
end: false,
|
||||
},
|
||||
async (req, res, next) => {
|
||||
req.user = owner;
|
||||
req.cookies = { "n8n-auth": "fake" };
|
||||
next();
|
||||
}
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
n8n: {
|
||||
ready: [disableUmHook],
|
||||
},
|
||||
};
|
||||
Reference in New Issue
Block a user