{"record":{"id":"d553df03c68236c5","repo":"louislam/dockge","slug":"dockge-has-been-initialized-if-you-want-to-run-se","errorCode":null,"errorMessage":"Dockge has been initialized. If you want to run setup again, please delete the database.","messagePattern":"Dockge has been initialized\\. If you want to run setup again, please delete the database\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"backend/socket-handlers/main-socket-handler.ts","lineNumber":39,"sourceCode":"import fs, { promises as fsAsync } from \"fs\";\nimport path from \"path\";\n\nexport class MainSocketHandler extends SocketHandler {\n    create(socket : DockgeSocket, server : DockgeServer) {\n\n        // ***************************\n        // Public Socket API\n        // ***************************\n\n        // Setup\n        socket.on(\"setup\", async (username, password, callback) => {\n            try {\n                if (passwordStrength(password).value === \"Too weak\") {\n                    throw new Error(\"Password is too weak. It should contain alphabetic and numeric characters. It must be at least 6 characters in length.\");\n                }\n\n                if ((await R.knex(\"user\").count(\"id as count\").first()).count !== 0) {\n                    throw new Error(\"Dockge has been initialized. If you want to run setup again, please delete the database.\");\n                }\n\n                const user = R.dispense(\"user\");\n                user.username = username;\n                user.password = generatePasswordHash(password);\n                await R.store(user);\n\n                server.needSetup = false;\n\n                callback({\n                    ok: true,\n                    msg: \"successAdded\",\n                    msgi18n: true,\n                });\n\n            } catch (e) {\n                if (e instanceof Error) {\n                    callback({","sourceCodeStart":21,"sourceCodeEnd":57,"githubUrl":"https://github.com/louislam/dockge/blob/f809ae192b571944ad773e9866d3e67064ae8043/backend/socket-handlers/main-socket-handler.ts#L21-L57","documentation":"The 'setup' socket handler is a one-time initialization path. Before creating the admin user it counts rows in the 'user' table via knex; if any user already exists the instance is considered initialized and this Error is thrown to prevent re-running setup. This protects existing accounts from being overwritten by a second setup call.","triggerScenarios":"Emitting the 'setup' socket event when the 'user' table already contains at least one row (server.needSetup is false).","commonSituations":"Re-running a provisioning script against an already-initialized Dockge instance; pointing a new frontend at an existing database file; attempting to reset a forgotten admin password by replaying setup instead of deleting the DB.","solutions":["Do not call 'setup' — the instance already has an admin account; log in instead.","To genuinely re-initialize, stop Dockge and delete the database file (data/stacks.db by default), then restart and run setup.","Reset the password via the changePassword flow after authenticating with the existing account."],"exampleFix":"// before (against initialized instance)\nsocket.emit('setup', 'admin', 'newpass1', cb);\n// after\nif (server.needSetup) {\n    socket.emit('setup', 'admin', 'newpass1', cb);\n} else {\n    socket.emit('login', 'admin', 'existingpass', cb);\n}","handlingStrategy":"validation","validationCode":"// Only run setup when the server reports it needs setup\nif (serverState.needSetup) {\n    socket.emit('setup', username, password, cb);\n} else {\n    socket.emit('login', username, password, cb);\n}","typeGuard":"function isFreshInstance(s) { return s.needSetup === true; }","tryCatchPattern":"socket.emit('setup', username, password, (res) => {\n    if (!res.ok && /initialized/.test(res.msg)) {\n        redirectToLogin();\n    }\n});","preventionTips":["Gate setup UI/flows on the server's needSetup flag","Check whether an admin can log in before attempting setup","Never delete the DB file unless a full re-init is intended"],"tags":["setup","initialization","database","authentication"],"backgroundTag":"already-initialized","analyzedSha":"f809ae192b571944ad773e9866d3e67064ae8043","analyzedAt":"2026-08-31T19:13:50.919Z","schemaVersion":2},"datasetVersion":"2026-08-31T22:30:34.772Z"}