{"record":{"id":"77b4ffc41dfaeadc","repo":"Dokploy/dokploy","slug":"unauthorized-77b4ff","errorCode":"UNAUTHORIZED","errorMessage":"You need to use a server to create a Postgres","messagePattern":"You need to use a server to create a Postgres","errorType":"exception","errorClass":"TRPCError","httpStatus":401,"severity":"error","filePath":"apps/dokploy/server/api/routers/postgres.ts","lineNumber":72,"sourceCode":"} from \"@/server/db/schema\";\nimport { cancelJobs } from \"@/server/utils/backup\";\n\nexport const postgresRouter = createTRPCRouter({\n\tcreate: protectedProcedure\n\t\t.input(apiCreatePostgres)\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 Postgres\",\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":54,"sourceCodeEnd":90,"githubUrl":"https://github.com/Dokploy/dokploy/blob/546686ea3587f12ec5652217dedd9f7960fb6d15/apps/dokploy/server/api/routers/postgres.ts#L54-L90","documentation":"Thrown by the createPostgres tRPC mutation when the deployment is Dokploy Cloud (IS_CLOUD) or the web server settings have remoteServersOnly enabled, but the request did not include a serverId. Dokploy requires databases to be pinned to an explicit server in these modes instead of defaulting to the local/web server.","triggerScenarios":"Calling postgres.create without input.serverId while IS_CLOUD=true or when getWebServerSettings() returns remoteServersOnly=true. Typically happens when a client built against self-hosted Dokploy (where serverId is optional) is used against Dokply Cloud.","commonSituations":"Self-hosted scripts/API clients reused against the cloud version; admin enabled 'remote servers only' in web server settings; frontend not sending the server selector value.","solutions":["Pass a serverId in the create request payload (e.g. from the servers dropdown / server.list API)","If self-hosted and this is unexpected, check Settings > Web Server and disable remoteServersOnly","Ensure the user has access to at least one server before creating a Postgres instance"],"exampleFix":"// before\nconst pg = await api.postgres.create.mutate({ name: 'db', projectId, envId });\n// after\nconst pg = await api.postgres.create.mutate({ name: 'db', projectId, envId, serverId: selectedServerId });","handlingStrategy":"validation","validationCode":"const servers = await api.server.list.query();\nif ((isCloud || settings.remoteServersOnly) && servers.length === 0) {\n  throw new Error('No servers available — cannot create Postgres');\n}\nconst payload = { ...input, serverId: input.serverId ?? servers[0]?.serverId };","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always populate the server selector before submitting create forms","Feature-detect cloud mode in your client and require serverId accordingly"],"tags":["dokploy","postgres","authorization","cloud","server-selection"],"backgroundTag":"missing-required-parameter","analyzedSha":"546686ea3587f12ec5652217dedd9f7960fb6d15","analyzedAt":"2026-08-27T05:18:58.095Z","schemaVersion":2},"datasetVersion":"2026-08-27T08:17:20.692Z"}