{"record":{"id":"5c62e607520a6a35","repo":"louislam/uptime-kuma","slug":"uptime-kuma-has-been-initialized-if-you-want-to-r","errorCode":null,"errorMessage":"Uptime Kuma has been initialized. If you want to run setup again, please delete the database.","messagePattern":"Uptime Kuma has been initialized\\. If you want to run setup again, please delete the database\\.","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"warning","filePath":"server/server.js","lineNumber":712,"sourceCode":"                callback({\n                    ok: false,\n                    msg: error.message,\n                });\n            }\n        });\n\n        socket.on(\"needSetup\", async (callback) => {\n            callback(needSetup);\n        });\n\n        socket.on(\"setup\", async (username, password, callback) => {\n            try {\n                if (passwordStrength(password).value === \"Too weak\") {\n                    throw new TranslatableError(\"passwordTooWeak\");\n                }\n\n                if ((await R.knex(\"user\").count(\"id as count\").first()).count !== 0) {\n                    throw new Error(\n                        \"Uptime Kuma has been initialized. If you want to run setup again, please delete the database.\"\n                    );\n                }\n\n                let user = R.dispense(\"user\");\n                user.username = username;\n                user.password = await passwordHash.generate(password);\n                await R.store(user);\n\n                needSetup = false;\n\n                callback({\n                    ok: true,\n                    msg: \"successAdded\",\n                    msgi18n: true,\n                });\n            } catch (e) {\n                callback({","sourceCodeStart":694,"sourceCodeEnd":730,"githubUrl":"https://github.com/louislam/uptime-kuma/blob/6b5ea0155793e666666745fb8d6fef1e829543a2/server/server.js#L694-L730","documentation":"Thrown by the 'setup' socket handler when the user table already contains at least one row (R.knex('user').count > 0). It prevents re-running initial setup on an already-initialized instance. The callback returns {ok:false, msg:'Uptime Kuma has been initialized...'}.","triggerScenarios":"Calling the 'setup' socket event on an instance that already has an admin user. Happens if the frontend setup screen is force-shown, or a client replays setup after installation completed.","commonSituations":"Stale frontend state showing the setup page after setup finished; a second browser tab attempting setup; DB restored with existing users; scripted setup run twice.","solutions":["Gate the setup UI on the 'needSetup' value returned by the server; do not show setup once it is false.","If you truly need to re-setup, delete the database as the message instructs (data loss).","Ensure only the initial request reaches 'setup'; treat subsequent calls as errors.","After successful setup, redirect all clients to the login page."],"exampleFix":"// before\nsocket.emit('setup', user, pw, cb); // always called\n\n// after\nsocket.emit('needSetup', (needSetup) => {\n  if (!needSetup) return router.push('/login');\n  socket.emit('setup', user, pw, cb);\n});","handlingStrategy":"validation","validationCode":"// Only call setup when the server reports it is needed\nsocket.emit('needSetup', (needSetup) => {\n  if (!needSetup) return router.push('/login');\n  // safe to proceed with setup\n});","typeGuard":"function shouldOfferSetup(needSetup) {\n  return needSetup === true;\n}","tryCatchPattern":null,"preventionTips":["Gate the setup screen on needSetup from the server.","After setup success, navigate all clients to login.","Never replay setup on an initialized instance.","If re-setup is truly required, delete the DB knowingly (data loss)."],"tags":["auth","setup","state","initialization","validation"],"backgroundTag":null,"analyzedSha":"6b5ea0155793e666666745fb8d6fef1e829543a2","analyzedAt":"2026-08-12T23:42:12.959Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}