{"record":{"id":"9fa9ed4ab25ae57e","repo":"Dokploy/dokploy","slug":"unauthorized-9fa9ed","errorCode":"UNAUTHORIZED","errorMessage":"You need to use a server to create a Libsql","messagePattern":"You need to use a server to create a Libsql","errorType":"exception","errorClass":"TRPCError","httpStatus":401,"severity":"error","filePath":"apps/dokploy/server/api/routers/libsql.ts","lineNumber":60,"sourceCode":"\tapiUpdateLibsql,\n\tlibsql as libsqlTable,\n} from \"@/server/db/schema\";\nexport const libsqlRouter = createTRPCRouter({\n\tcreate: protectedProcedure\n\t\t.input(apiCreateLibsql)\n\t\t.mutation(async ({ input, ctx }) => {\n\t\t\ttry {\n\t\t\t\tconst environment = await findEnvironmentById(input.environmentId);\n\t\t\t\tconst project = await findProjectById(environment.projectId);\n\n\t\t\t\tawait checkServiceAccess(ctx, project.projectId, \"create\");\n\n\t\t\t\tconst webServerSettings = await getWebServerSettings();\n\t\t\t\tif (\n\t\t\t\t\t(IS_CLOUD || webServerSettings?.remoteServersOnly) &&\n\t\t\t\t\t!input.serverId\n\t\t\t\t) {\n\t\t\t\t\tthrow new TRPCError({\n\t\t\t\t\t\tcode: \"UNAUTHORIZED\",\n\t\t\t\t\t\tmessage: \"You need to use a server to create a Libsql\",\n\t\t\t\t\t});\n\t\t\t\t}\n\n\t\t\t\tif (project.organizationId !== ctx.session.activeOrganizationId) {\n\t\t\t\t\tthrow new TRPCError({\n\t\t\t\t\t\tcode: \"UNAUTHORIZED\",\n\t\t\t\t\t\tmessage: \"You are not authorized to access this project\",\n\t\t\t\t\t});\n\t\t\t\t}\n\n\t\t\t\tif (input.serverId) {\n\t\t\t\t\tconst accessibleIds = await getAccessibleServerIds(ctx.session);\n\t\t\t\t\tif (!accessibleIds.has(input.serverId)) {\n\t\t\t\t\t\tthrow new TRPCError({\n\t\t\t\t\t\t\tcode: \"UNAUTHORIZED\",\n\t\t\t\t\t\t\tmessage: \"You are not authorized to access this server\",","sourceCodeStart":42,"sourceCodeEnd":78,"githubUrl":"https://github.com/Dokploy/dokploy/blob/546686ea3587f12ec5652217dedd9f7960fb6d15/apps/dokploy/server/api/routers/libsql.ts#L42-L78","documentation":"On Dokploy Cloud (or self-hosted with remoteServersOnly enabled), Libsql databases must be deployed to a designated remote server. The create procedure rejects requests that omit serverId in that mode with UNAUTHORIZED — effectively a tenancy/deployment-target policy, not a real auth failure.","triggerScenarios":"Creating a Libsql database without serverId while IS_CLOUD=true or webServerSettings.remoteServersOnly is set.","commonSituations":"Cloud users (or self-hosted admins who enabled remote-servers-only) using a client/API call written for the local-server model; frontend bug that drops the serverId field.","solutions":["Pass a valid serverId that the organization can access","If self-hosted and you intended local deployment, disable remoteServersOnly in web server settings","Create/pick a server first, then reference its id in the create call"],"exampleFix":"// before\nawait api.libsql.create.mutate({ name: \"db\", projectId });\n// after\nawait api.libsql.create.mutate({ name: \"db\", projectId, serverId });","handlingStrategy":"validation","validationCode":"const servers = await api.server.list.query();\nif (isCloudOrRemoteOnly && servers.length === 0) throw new Error(\"create a server first\");\nconst serverId = servers[0]?.serverId;","typeGuard":null,"tryCatchPattern":null,"preventionTips":["On Cloud/remote-only mode always provision a server before creating databases","Keep create forms serverId-aware"],"tags":["libsql","cloud","deployment-target","validation","trpc"],"backgroundTag":"missing-required-parameter","analyzedSha":"546686ea3587f12ec5652217dedd9f7960fb6d15","analyzedAt":"2026-08-27T05:18:58.095Z","schemaVersion":2},"datasetVersion":"2026-08-27T08:17:20.692Z"}