diff --git a/apps/dokploy/pages/dashboard/docker.tsx b/apps/dokploy/pages/dashboard/docker.tsx index 051e4f0a..202935aa 100644 --- a/apps/dokploy/pages/dashboard/docker.tsx +++ b/apps/dokploy/pages/dashboard/docker.tsx @@ -1,7 +1,8 @@ import { ShowContainers } from "@/components/dashboard/docker/show/show-containers"; import { DashboardLayout } from "@/components/layouts/dashboard-layout"; import { appRouter } from "@/server/api/root"; -import { IS_CLOUD, validateRequest } from "@dokploy/server"; +import { IS_CLOUD } from "@dokploy/server/constants"; +import { validateRequest } from "@dokploy/server/lib/auth"; import { createServerSideHelpers } from "@trpc/react-query/server"; import type { GetServerSidePropsContext } from "next"; import React, { type ReactElement } from "react"; @@ -27,7 +28,7 @@ export async function getServerSideProps( }, }; } - const { user, session } = await validateRequest(ctx.req, ctx.res); + const { user, session } = await validateRequest(ctx.req); if (!user) { return { redirect: { @@ -44,21 +45,20 @@ export async function getServerSideProps( req: req as any, res: res as any, db: null as any, - session: session, - user: user, + session: session as any, + user: user as any, }, transformer: superjson, }); try { await helpers.project.all.prefetch(); - const auth = await helpers.auth.get.fetch(); - if (auth.role === "member") { - const user = await helpers.user.byAuthId.fetch({ - authId: auth.id, + if (user.role === "member") { + const userR = await helpers.user.get.fetch({ + userId: user.id, }); - if (!user.canAccessToDocker) { + if (!userR.canAccessToDocker) { return { redirect: { permanent: true, diff --git a/apps/dokploy/pages/dashboard/monitoring.tsx b/apps/dokploy/pages/dashboard/monitoring.tsx index a9f712f3..a30706fc 100644 --- a/apps/dokploy/pages/dashboard/monitoring.tsx +++ b/apps/dokploy/pages/dashboard/monitoring.tsx @@ -8,7 +8,7 @@ import { Switch } from "@/components/ui/switch"; import { useLocalStorage } from "@/hooks/useLocalStorage"; import { api } from "@/utils/api"; import { IS_CLOUD } from "@dokploy/server/constants"; -import { validateRequest } from "@dokploy/server/index"; +import { validateRequest } from "@dokploy/server/lib/auth"; import { Loader2 } from "lucide-react"; import type { GetServerSidePropsContext } from "next"; import type React from "react"; @@ -104,7 +104,7 @@ export async function getServerSideProps( }, }; } - const { user } = await validateRequest(ctx.req, ctx.res); + const { user } = await validateRequest(ctx.req); if (!user) { return { redirect: { diff --git a/apps/dokploy/pages/dashboard/project/[projectId].tsx b/apps/dokploy/pages/dashboard/project/[projectId].tsx index 87fa3df4..b5d6b18f 100644 --- a/apps/dokploy/pages/dashboard/project/[projectId].tsx +++ b/apps/dokploy/pages/dashboard/project/[projectId].tsx @@ -49,7 +49,7 @@ import { cn } from "@/lib/utils"; import { appRouter } from "@/server/api/root"; import { api } from "@/utils/api"; import type { findProjectById } from "@dokploy/server"; -import { validateRequest } from "@dokploy/server"; +import { validateRequest } from "@dokploy/server/lib/auth"; import { createServerSideHelpers } from "@trpc/react-query/server"; import { Ban, @@ -658,7 +658,7 @@ export async function getServerSideProps( const { params } = ctx; const { req, res } = ctx; - const { user, session } = await validateRequest(req, res); + const { user, session } = await validateRequest(req); if (!user) { return { redirect: { diff --git a/apps/dokploy/pages/dashboard/project/[projectId]/services/application/[applicationId].tsx b/apps/dokploy/pages/dashboard/project/[projectId]/services/application/[applicationId].tsx index 441720b9..a394f320 100644 --- a/apps/dokploy/pages/dashboard/project/[projectId]/services/application/[applicationId].tsx +++ b/apps/dokploy/pages/dashboard/project/[projectId]/services/application/[applicationId].tsx @@ -39,7 +39,8 @@ import { import { cn } from "@/lib/utils"; import { appRouter } from "@/server/api/root"; import { api } from "@/utils/api"; -import { validateRequest } from "@dokploy/server"; +import { validateRequest } from "@dokploy/server/lib/auth"; +// import { validateRequest } from "@dokploy/server"; import { createServerSideHelpers } from "@trpc/react-query/server"; import copy from "copy-to-clipboard"; import { GlobeIcon, HelpCircle, ServerOff, Trash2 } from "lucide-react"; @@ -370,7 +371,7 @@ export async function getServerSideProps( const { query, params, req, res } = ctx; const activeTab = query.tab; - const { user, session } = await validateRequest(req, res); + const { user, session } = await validateRequest(req); if (!user) { return { redirect: { diff --git a/apps/dokploy/pages/dashboard/project/[projectId]/services/compose/[composeId].tsx b/apps/dokploy/pages/dashboard/project/[projectId]/services/compose/[composeId].tsx index 41a346b4..8bd3e863 100644 --- a/apps/dokploy/pages/dashboard/project/[projectId]/services/compose/[composeId].tsx +++ b/apps/dokploy/pages/dashboard/project/[projectId]/services/compose/[composeId].tsx @@ -33,7 +33,7 @@ import { import { cn } from "@/lib/utils"; import { appRouter } from "@/server/api/root"; import { api } from "@/utils/api"; -import { validateRequest } from "@dokploy/server"; +import { validateRequest } from "@dokploy/server/lib/auth"; import { createServerSideHelpers } from "@trpc/react-query/server"; import copy from "copy-to-clipboard"; import { CircuitBoard, ServerOff } from "lucide-react"; @@ -366,7 +366,7 @@ export async function getServerSideProps( const { query, params, req, res } = ctx; const activeTab = query.tab; - const { user, session } = await validateRequest(req, res); + const { user, session } = await validateRequest(req); if (!user) { return { redirect: { diff --git a/apps/dokploy/pages/dashboard/project/[projectId]/services/mariadb/[mariadbId].tsx b/apps/dokploy/pages/dashboard/project/[projectId]/services/mariadb/[mariadbId].tsx index 7138be02..9adbad15 100644 --- a/apps/dokploy/pages/dashboard/project/[projectId]/services/mariadb/[mariadbId].tsx +++ b/apps/dokploy/pages/dashboard/project/[projectId]/services/mariadb/[mariadbId].tsx @@ -35,7 +35,7 @@ import { import { cn } from "@/lib/utils"; import { appRouter } from "@/server/api/root"; import { api } from "@/utils/api"; -import { validateRequest } from "@dokploy/server"; +import { validateRequest } from "@dokploy/server/lib/auth"; import { createServerSideHelpers } from "@trpc/react-query/server"; import { HelpCircle, ServerOff, Trash2 } from "lucide-react"; import type { @@ -316,7 +316,7 @@ export async function getServerSideProps( const { query, params, req, res } = ctx; const activeTab = query.tab; - const { user, session } = await validateRequest(req, res); + const { user, session } = await validateRequest(req); if (!user) { return { redirect: { diff --git a/apps/dokploy/pages/dashboard/project/[projectId]/services/mongo/[mongoId].tsx b/apps/dokploy/pages/dashboard/project/[projectId]/services/mongo/[mongoId].tsx index c0ddd96d..a5ba6b5d 100644 --- a/apps/dokploy/pages/dashboard/project/[projectId]/services/mongo/[mongoId].tsx +++ b/apps/dokploy/pages/dashboard/project/[projectId]/services/mongo/[mongoId].tsx @@ -35,7 +35,7 @@ import { import { cn } from "@/lib/utils"; import { appRouter } from "@/server/api/root"; import { api } from "@/utils/api"; -import { validateRequest } from "@dokploy/server"; +import { validateRequest } from "@dokploy/server/lib/auth"; import { createServerSideHelpers } from "@trpc/react-query/server"; import { HelpCircle, ServerOff, Trash2 } from "lucide-react"; import type { @@ -318,7 +318,7 @@ export async function getServerSideProps( const { query, params, req, res } = ctx; const activeTab = query.tab; - const { user, session } = await validateRequest(req, res); + const { user, session } = await validateRequest(req); if (!user) { return { redirect: { diff --git a/apps/dokploy/pages/dashboard/project/[projectId]/services/mysql/[mysqlId].tsx b/apps/dokploy/pages/dashboard/project/[projectId]/services/mysql/[mysqlId].tsx index d170bb76..3e17c4fa 100644 --- a/apps/dokploy/pages/dashboard/project/[projectId]/services/mysql/[mysqlId].tsx +++ b/apps/dokploy/pages/dashboard/project/[projectId]/services/mysql/[mysqlId].tsx @@ -35,7 +35,7 @@ import { import { cn } from "@/lib/utils"; import { appRouter } from "@/server/api/root"; import { api } from "@/utils/api"; -import { validateRequest } from "@dokploy/server"; +import { validateRequest } from "@dokploy/server/lib/auth"; import { createServerSideHelpers } from "@trpc/react-query/server"; import { HelpCircle, ServerOff, Trash2 } from "lucide-react"; import type { @@ -323,7 +323,7 @@ export async function getServerSideProps( const { query, params, req, res } = ctx; const activeTab = query.tab; - const { user, session } = await validateRequest(req, res); + const { user, session } = await validateRequest(req); if (!user) { return { redirect: { diff --git a/apps/dokploy/pages/dashboard/project/[projectId]/services/postgres/[postgresId].tsx b/apps/dokploy/pages/dashboard/project/[projectId]/services/postgres/[postgresId].tsx index 67c6a4a5..0b1d2aee 100644 --- a/apps/dokploy/pages/dashboard/project/[projectId]/services/postgres/[postgresId].tsx +++ b/apps/dokploy/pages/dashboard/project/[projectId]/services/postgres/[postgresId].tsx @@ -35,7 +35,7 @@ import { import { cn } from "@/lib/utils"; import { appRouter } from "@/server/api/root"; import { api } from "@/utils/api"; -import { validateRequest } from "@dokploy/server"; +import { validateRequest } from "@dokploy/server/lib/auth"; import { createServerSideHelpers } from "@trpc/react-query/server"; import { HelpCircle, ServerOff, Trash2 } from "lucide-react"; import type { @@ -319,7 +319,7 @@ export async function getServerSideProps( ) { const { query, params, req, res } = ctx; const activeTab = query.tab; - const { user, session } = await validateRequest(req, res); + const { user, session } = await validateRequest(req); if (!user) { return { redirect: { diff --git a/apps/dokploy/pages/dashboard/project/[projectId]/services/redis/[redisId].tsx b/apps/dokploy/pages/dashboard/project/[projectId]/services/redis/[redisId].tsx index bb9ebc4a..853e6688 100644 --- a/apps/dokploy/pages/dashboard/project/[projectId]/services/redis/[redisId].tsx +++ b/apps/dokploy/pages/dashboard/project/[projectId]/services/redis/[redisId].tsx @@ -34,7 +34,7 @@ import { import { cn } from "@/lib/utils"; import { appRouter } from "@/server/api/root"; import { api } from "@/utils/api"; -import { validateRequest } from "@dokploy/server"; +import { validateRequest } from "@dokploy/server/lib/auth"; import { createServerSideHelpers } from "@trpc/react-query/server"; import { HelpCircle, ServerOff } from "lucide-react"; import type { @@ -311,7 +311,7 @@ export async function getServerSideProps( const { query, params, req, res } = ctx; const activeTab = query.tab; - const { user, session } = await validateRequest(req, res); + const { user, session } = await validateRequest(req); if (!user) { return { redirect: { diff --git a/apps/dokploy/pages/dashboard/projects.tsx b/apps/dokploy/pages/dashboard/projects.tsx index af4d0f1e..abeee669 100644 --- a/apps/dokploy/pages/dashboard/projects.tsx +++ b/apps/dokploy/pages/dashboard/projects.tsx @@ -2,7 +2,7 @@ import { ShowProjects } from "@/components/dashboard/projects/show"; import { DashboardLayout } from "@/components/layouts/dashboard-layout"; import { appRouter } from "@/server/api/root"; import { api } from "@/utils/api"; -import { validateRequest } from "@dokploy/server"; +import { validateRequest } from "@dokploy/server/lib/auth"; import { createServerSideHelpers } from "@trpc/react-query/server"; import type { GetServerSidePropsContext } from "next"; import dynamic from "next/dynamic"; @@ -38,7 +38,7 @@ export async function getServerSideProps( ctx: GetServerSidePropsContext<{ serviceId: string }>, ) { const { req, res } = ctx; - const { user, session } = await validateRequest(req, res); + const { user, session } = await validateRequest(req); const helpers = createServerSideHelpers({ router: appRouter, @@ -46,8 +46,8 @@ export async function getServerSideProps( req: req as any, res: res as any, db: null as any, - session: session, - user: user, + session: session as any, + user: user as any, }, transformer: superjson, }); diff --git a/apps/dokploy/pages/dashboard/requests.tsx b/apps/dokploy/pages/dashboard/requests.tsx index d1a927e3..580b936a 100644 --- a/apps/dokploy/pages/dashboard/requests.tsx +++ b/apps/dokploy/pages/dashboard/requests.tsx @@ -1,6 +1,7 @@ import { ShowRequests } from "@/components/dashboard/requests/show-requests"; import { DashboardLayout } from "@/components/layouts/dashboard-layout"; -import { IS_CLOUD, validateRequest } from "@dokploy/server"; +import { IS_CLOUD } from "@dokploy/server/constants"; +import { validateRequest } from "@dokploy/server/lib/auth"; import type { GetServerSidePropsContext } from "next"; import type { ReactElement } from "react"; import * as React from "react"; @@ -22,7 +23,7 @@ export async function getServerSideProps( }, }; } - const { user } = await validateRequest(ctx.req, ctx.res); + const { user } = await validateRequest(ctx.req); if (!user) { return { redirect: { diff --git a/apps/dokploy/pages/dashboard/settings/billing.tsx b/apps/dokploy/pages/dashboard/settings/billing.tsx index b1a7cb21..3acce0b0 100644 --- a/apps/dokploy/pages/dashboard/settings/billing.tsx +++ b/apps/dokploy/pages/dashboard/settings/billing.tsx @@ -2,7 +2,8 @@ import { ShowBilling } from "@/components/dashboard/settings/billing/show-billin import { DashboardLayout } from "@/components/layouts/dashboard-layout"; import { appRouter } from "@/server/api/root"; -import { IS_CLOUD, validateRequest } from "@dokploy/server"; +import { IS_CLOUD } from "@dokploy/server/constants"; +import { validateRequest } from "@dokploy/server/lib/auth"; import { createServerSideHelpers } from "@trpc/react-query/server"; import type { GetServerSidePropsContext } from "next"; import React, { type ReactElement } from "react"; @@ -29,7 +30,7 @@ export async function getServerSideProps( }; } const { req, res } = ctx; - const { user, session } = await validateRequest(req, res); + const { user, session } = await validateRequest(req); if (!user || user.role === "member") { return { redirect: { @@ -45,8 +46,8 @@ export async function getServerSideProps( req: req as any, res: res as any, db: null as any, - session: session, - user: user, + session: session as any, + user: user as any, }, transformer: superjson, }); diff --git a/apps/dokploy/pages/dashboard/swarm.tsx b/apps/dokploy/pages/dashboard/swarm.tsx index f5772820..8278ed18 100644 --- a/apps/dokploy/pages/dashboard/swarm.tsx +++ b/apps/dokploy/pages/dashboard/swarm.tsx @@ -1,7 +1,8 @@ import SwarmMonitorCard from "@/components/dashboard/swarm/monitoring-card"; import { DashboardLayout } from "@/components/layouts/dashboard-layout"; import { appRouter } from "@/server/api/root"; -import { IS_CLOUD, validateRequest } from "@dokploy/server"; +import { IS_CLOUD } from "@dokploy/server/constants"; +import { validateRequest } from "@dokploy/server/lib/auth"; import { createServerSideHelpers } from "@trpc/react-query/server"; import type { GetServerSidePropsContext } from "next"; import type { ReactElement } from "react"; @@ -27,7 +28,7 @@ export async function getServerSideProps( }, }; } - const { user, session } = await validateRequest(ctx.req, ctx.res); + const { user, session } = await validateRequest(ctx.req); if (!user) { return { redirect: { @@ -44,21 +45,20 @@ export async function getServerSideProps( req: req as any, res: res as any, db: null as any, - session: session, - user: user, + session: session as any, + user: user as any, }, transformer: superjson, }); try { await helpers.project.all.prefetch(); - const auth = await helpers.auth.get.fetch(); - if (auth.role === "member") { - const user = await helpers.user.byAuthId.fetch({ - authId: auth.id, + if (user.role === "member") { + const userR = await helpers.user.get.fetch({ + userId: user.id, }); - if (!user.canAccessToDocker) { + if (!userR.canAccessToDocker) { return { redirect: { permanent: true, diff --git a/apps/dokploy/pages/dashboard/traefik.tsx b/apps/dokploy/pages/dashboard/traefik.tsx index 1f710c9e..6939eabd 100644 --- a/apps/dokploy/pages/dashboard/traefik.tsx +++ b/apps/dokploy/pages/dashboard/traefik.tsx @@ -1,7 +1,8 @@ import { ShowTraefikSystem } from "@/components/dashboard/file-system/show-traefik-system"; import { DashboardLayout } from "@/components/layouts/dashboard-layout"; import { appRouter } from "@/server/api/root"; -import { IS_CLOUD, validateRequest } from "@dokploy/server"; +import { IS_CLOUD } from "@dokploy/server/constants"; +import { validateRequest } from "@dokploy/server/lib/auth"; import { createServerSideHelpers } from "@trpc/react-query/server"; import type { GetServerSidePropsContext } from "next"; import React, { type ReactElement } from "react"; @@ -27,7 +28,7 @@ export async function getServerSideProps( }, }; } - const { user, session } = await validateRequest(ctx.req, ctx.res); + const { user, session } = await validateRequest(ctx.req); if (!user) { return { redirect: { @@ -44,21 +45,20 @@ export async function getServerSideProps( req: req as any, res: res as any, db: null as any, - session: session, - user: user, + session: session as any, + user: user as any, }, transformer: superjson, }); try { await helpers.project.all.prefetch(); - const auth = await helpers.auth.get.fetch(); - if (auth.role === "member") { - const user = await helpers.user.byAuthId.fetch({ - authId: auth.id, + if (user.role === "member") { + const userR = await helpers.user.get.fetch({ + userId: user.id, }); - if (!user.canAccessToTraefikFiles) { + if (!userR.canAccessToTraefikFiles) { return { redirect: { permanent: true, diff --git a/apps/dokploy/server/api/routers/compose.ts b/apps/dokploy/server/api/routers/compose.ts index 69586eb4..a74c2bfb 100644 --- a/apps/dokploy/server/api/routers/compose.ts +++ b/apps/dokploy/server/api/routers/compose.ts @@ -72,7 +72,7 @@ export const composeRouter = createTRPCRouter({ }); } const project = await findProjectById(input.projectId); - if (project.userId !== ctx.user.ownerId) { + if (project.organizationId !== ctx.session.activeOrganizationId) { throw new TRPCError({ code: "UNAUTHORIZED", message: "You are not authorized to access this project", @@ -98,7 +98,7 @@ export const composeRouter = createTRPCRouter({ } const compose = await findComposeById(input.composeId); - if (compose.project.userId !== ctx.user.ownerId) { + if (compose.project.organizationId !== ctx.session.activeOrganizationId) { throw new TRPCError({ code: "UNAUTHORIZED", message: "You are not authorized to access this compose", @@ -111,7 +111,7 @@ export const composeRouter = createTRPCRouter({ .input(apiUpdateCompose) .mutation(async ({ input, ctx }) => { const compose = await findComposeById(input.composeId); - if (compose.project.userId !== ctx.user.ownerId) { + if (compose.project.organizationId !== ctx.session.activeOrganizationId) { throw new TRPCError({ code: "UNAUTHORIZED", message: "You are not authorized to update this compose", @@ -127,7 +127,10 @@ export const composeRouter = createTRPCRouter({ } const composeResult = await findComposeById(input.composeId); - if (composeResult.project.userId !== ctx.user.ownerId) { + if ( + composeResult.project.organizationId !== + ctx.session.activeOrganizationId + ) { throw new TRPCError({ code: "UNAUTHORIZED", message: "You are not authorized to delete this compose", @@ -158,7 +161,7 @@ export const composeRouter = createTRPCRouter({ .input(apiFindCompose) .mutation(async ({ input, ctx }) => { const compose = await findComposeById(input.composeId); - if (compose.project.userId !== ctx.user.ownerId) { + if (compose.project.organizationId !== ctx.session.activeOrganizationId) { throw new TRPCError({ code: "UNAUTHORIZED", message: "You are not authorized to clean this compose", @@ -171,7 +174,7 @@ export const composeRouter = createTRPCRouter({ .input(apiFetchServices) .query(async ({ input, ctx }) => { const compose = await findComposeById(input.composeId); - if (compose.project.userId !== ctx.user.ownerId) { + if (compose.project.organizationId !== ctx.session.activeOrganizationId) { throw new TRPCError({ code: "UNAUTHORIZED", message: "You are not authorized to load this compose", @@ -185,7 +188,9 @@ export const composeRouter = createTRPCRouter({ try { const compose = await findComposeById(input.composeId); - if (compose.project.userId !== ctx.user.ownerId) { + if ( + compose.project.organizationId !== ctx.session.activeOrganizationId + ) { throw new TRPCError({ code: "UNAUTHORIZED", message: "You are not authorized to fetch this compose", @@ -210,7 +215,7 @@ export const composeRouter = createTRPCRouter({ .input(apiRandomizeCompose) .mutation(async ({ input, ctx }) => { const compose = await findComposeById(input.composeId); - if (compose.project.userId !== ctx.user.ownerId) { + if (compose.project.organizationId !== ctx.session.activeOrganizationId) { throw new TRPCError({ code: "UNAUTHORIZED", message: "You are not authorized to randomize this compose", @@ -222,7 +227,7 @@ export const composeRouter = createTRPCRouter({ .input(apiRandomizeCompose) .mutation(async ({ input, ctx }) => { const compose = await findComposeById(input.composeId); - if (compose.project.userId !== ctx.user.ownerId) { + if (compose.project.organizationId !== ctx.session.activeOrganizationId) { throw new TRPCError({ code: "UNAUTHORIZED", message: "You are not authorized to randomize this compose", @@ -237,7 +242,7 @@ export const composeRouter = createTRPCRouter({ .input(apiFindCompose) .query(async ({ input, ctx }) => { const compose = await findComposeById(input.composeId); - if (compose.project.userId !== ctx.user.ownerId) { + if (compose.project.organizationId !== ctx.session.activeOrganizationId) { throw new TRPCError({ code: "UNAUTHORIZED", message: "You are not authorized to get this compose", @@ -255,7 +260,7 @@ export const composeRouter = createTRPCRouter({ .mutation(async ({ input, ctx }) => { const compose = await findComposeById(input.composeId); - if (compose.project.userId !== ctx.user.ownerId) { + if (compose.project.organizationId !== ctx.session.activeOrganizationId) { throw new TRPCError({ code: "UNAUTHORIZED", message: "You are not authorized to deploy this compose", @@ -288,7 +293,7 @@ export const composeRouter = createTRPCRouter({ .input(apiFindCompose) .mutation(async ({ input, ctx }) => { const compose = await findComposeById(input.composeId); - if (compose.project.userId !== ctx.user.ownerId) { + if (compose.project.organizationId !== ctx.session.activeOrganizationId) { throw new TRPCError({ code: "UNAUTHORIZED", message: "You are not authorized to redeploy this compose", @@ -320,7 +325,7 @@ export const composeRouter = createTRPCRouter({ .input(apiFindCompose) .mutation(async ({ input, ctx }) => { const compose = await findComposeById(input.composeId); - if (compose.project.userId !== ctx.user.ownerId) { + if (compose.project.organizationId !== ctx.session.activeOrganizationId) { throw new TRPCError({ code: "UNAUTHORIZED", message: "You are not authorized to stop this compose", @@ -334,7 +339,7 @@ export const composeRouter = createTRPCRouter({ .input(apiFindCompose) .mutation(async ({ input, ctx }) => { const compose = await findComposeById(input.composeId); - if (compose.project.userId !== ctx.user.ownerId) { + if (compose.project.organizationId !== ctx.session.activeOrganizationId) { throw new TRPCError({ code: "UNAUTHORIZED", message: "You are not authorized to stop this compose", @@ -349,7 +354,7 @@ export const composeRouter = createTRPCRouter({ .query(async ({ input, ctx }) => { const compose = await findComposeById(input.composeId); - if (compose.project.userId !== ctx.user.ownerId) { + if (compose.project.organizationId !== ctx.session.activeOrganizationId) { throw new TRPCError({ code: "UNAUTHORIZED", message: "You are not authorized to get this compose", @@ -362,7 +367,7 @@ export const composeRouter = createTRPCRouter({ .input(apiFindCompose) .mutation(async ({ input, ctx }) => { const compose = await findComposeById(input.composeId); - if (compose.project.userId !== ctx.user.ownerId) { + if (compose.project.organizationId !== ctx.session.activeOrganizationId) { throw new TRPCError({ code: "UNAUTHORIZED", message: "You are not authorized to refresh this compose", diff --git a/apps/dokploy/server/api/routers/notification.ts b/apps/dokploy/server/api/routers/notification.ts index 45170006..bba6c7db 100644 --- a/apps/dokploy/server/api/routers/notification.ts +++ b/apps/dokploy/server/api/routers/notification.ts @@ -57,7 +57,10 @@ export const notificationRouter = createTRPCRouter({ .input(apiCreateSlack) .mutation(async ({ input, ctx }) => { try { - return await createSlackNotification(input, ctx.user.ownerId); + return await createSlackNotification( + input, + ctx.session.activeOrganizationId, + ); } catch (error) { throw new TRPCError({ code: "BAD_REQUEST", @@ -80,7 +83,7 @@ export const notificationRouter = createTRPCRouter({ } return await updateSlackNotification({ ...input, - userId: ctx.user.ownerId, + organizationId: ctx.session.activeOrganizationId, }); } catch (error) { throw error; @@ -131,7 +134,7 @@ export const notificationRouter = createTRPCRouter({ } return await updateTelegramNotification({ ...input, - userId: ctx.user.ownerId, + organizationId: ctx.session.activeOrganizationId, }); } catch (error) { throw new TRPCError({ @@ -183,7 +186,7 @@ export const notificationRouter = createTRPCRouter({ } return await updateDiscordNotification({ ...input, - userId: ctx.user.ownerId, + organizationId: ctx.session.activeOrganizationId, }); } catch (error) { throw new TRPCError({ @@ -243,7 +246,7 @@ export const notificationRouter = createTRPCRouter({ } return await updateEmailNotification({ ...input, - userId: ctx.user.ownerId, + organizationId: ctx.session.activeOrganizationId, }); } catch (error) { throw new TRPCError({ @@ -314,13 +317,7 @@ export const notificationRouter = createTRPCRouter({ gotify: true, }, orderBy: desc(notifications.createdAt), - ...(IS_CLOUD && { - where: eq( - notifications.organizationId, - ctx.session.activeOrganizationId, - ), - }), - // TODO: Remove this line when the cloud version is ready + where: eq(notifications.organizationId, ctx.session.activeOrganizationId), }); }), receiveNotification: publicProcedure @@ -337,7 +334,7 @@ export const notificationRouter = createTRPCRouter({ ) .mutation(async ({ input }) => { try { - let userId = ""; + let organizationId = ""; let ServerName = ""; if (input.ServerType === "Dokploy") { const result = await db @@ -354,7 +351,7 @@ export const notificationRouter = createTRPCRouter({ }); } - userId = result?.[0]?.id; + organizationId = result?.[0]?.id; ServerName = "Dokploy"; } else { const result = await db @@ -364,18 +361,18 @@ export const notificationRouter = createTRPCRouter({ sql`${server.metricsConfig}::jsonb -> 'server' ->> 'token' = ${input.Token}`, ); - if (!result?.[0]?.userId) { + if (!result?.[0]?.organizationId) { throw new TRPCError({ code: "BAD_REQUEST", message: "Token not found", }); } - userId = result?.[0]?.userId; + organizationId = result?.[0]?.organizationId; ServerName = "Remote"; } - await sendServerThresholdNotifications(userId, { + await sendServerThresholdNotifications(organizationId, { ...input, ServerName, }); @@ -416,7 +413,7 @@ export const notificationRouter = createTRPCRouter({ } return await updateGotifyNotification({ ...input, - userId: ctx.user.ownerId, + organizationId: ctx.session.activeOrganizationId, }); } catch (error) { throw error; diff --git a/apps/dokploy/server/api/routers/project.ts b/apps/dokploy/server/api/routers/project.ts index 88bb21d7..b5beadf4 100644 --- a/apps/dokploy/server/api/routers/project.ts +++ b/apps/dokploy/server/api/routers/project.ts @@ -49,7 +49,10 @@ export const projectRouter = createTRPCRouter({ }); } - const project = await createProject(input, ctx.user.ownerId); + const project = await createProject( + input, + ctx.session.activeOrganizationId, + ); if (ctx.user.rol === "member") { await addNewProject(ctx.user.id, project.projectId); } diff --git a/apps/dokploy/server/api/routers/ssh-key.ts b/apps/dokploy/server/api/routers/ssh-key.ts index 90f7cd6e..d55a2379 100644 --- a/apps/dokploy/server/api/routers/ssh-key.ts +++ b/apps/dokploy/server/api/routers/ssh-key.ts @@ -41,10 +41,7 @@ export const sshRouter = createTRPCRouter({ .mutation(async ({ input, ctx }) => { try { const sshKey = await findSSHKeyById(input.sshKeyId); - if ( - IS_CLOUD && - sshKey.organizationId !== ctx.session.activeOrganizationId - ) { + if (sshKey.organizationId !== ctx.session.activeOrganizationId) { // TODO: Remove isCloud in the next versions of dokploy throw new TRPCError({ code: "UNAUTHORIZED", @@ -62,11 +59,7 @@ export const sshRouter = createTRPCRouter({ .query(async ({ input, ctx }) => { const sshKey = await findSSHKeyById(input.sshKeyId); - if ( - IS_CLOUD && - sshKey.organizationId !== ctx.session.activeOrganizationId - ) { - // TODO: Remove isCloud in the next versions of dokploy + if (sshKey.organizationId !== ctx.session.activeOrganizationId) { throw new TRPCError({ code: "UNAUTHORIZED", message: "You are not allowed to access this SSH key", @@ -76,12 +69,9 @@ export const sshRouter = createTRPCRouter({ }), all: protectedProcedure.query(async ({ ctx }) => { return await db.query.sshKeys.findMany({ - ...(IS_CLOUD && { - where: eq(sshKeys.organizationId, ctx.session.activeOrganizationId), - }), + where: eq(sshKeys.organizationId, ctx.session.activeOrganizationId), orderBy: desc(sshKeys.createdAt), }); - // TODO: Remove this line when the cloud version is ready }), generate: protectedProcedure .input(apiGenerateSSHKey) @@ -93,11 +83,7 @@ export const sshRouter = createTRPCRouter({ .mutation(async ({ input, ctx }) => { try { const sshKey = await findSSHKeyById(input.sshKeyId); - if ( - IS_CLOUD && - sshKey.organizationId !== ctx.session.activeOrganizationId - ) { - // TODO: Remove isCloud in the next versions of dokploy + if (sshKey.organizationId !== ctx.session.activeOrganizationId) { throw new TRPCError({ code: "UNAUTHORIZED", message: "You are not allowed to update this SSH key", diff --git a/apps/dokploy/server/api/routers/user.ts b/apps/dokploy/server/api/routers/user.ts index ccf9e5bc..269da8f5 100644 --- a/apps/dokploy/server/api/routers/user.ts +++ b/apps/dokploy/server/api/routers/user.ts @@ -5,6 +5,7 @@ import { member } from "@dokploy/server/db/schema"; import { TRPCError } from "@trpc/server"; import { eq } from "drizzle-orm"; import { adminProcedure, createTRPCRouter, protectedProcedure } from "../trpc"; +import { z } from "zod"; export const userRouter = createTRPCRouter({ all: adminProcedure.query(async ({ ctx }) => { return await db.query.member.findMany({ @@ -14,16 +15,20 @@ export const userRouter = createTRPCRouter({ }, }); }), - byAuthId: protectedProcedure - .input(apiFindOneUserByAuth) + get: protectedProcedure + .input( + z.object({ + userId: z.string(), + }), + ) .query(async ({ input, ctx }) => { - const user = await findUserByAuthId(input.authId); - if (user.adminId !== ctx.user.adminId) { - throw new TRPCError({ - code: "UNAUTHORIZED", - message: "You are not allowed to access this user", - }); - } + const user = await findUserById(input.userId); + // if (user.adminId !== ctx.user.adminId) { + // throw new TRPCError({ + // code: "UNAUTHORIZED", + // message: "You are not allowed to access this user", + // }); + // } return user; }), byUserId: protectedProcedure diff --git a/packages/server/src/db/schema/notification.ts b/packages/server/src/db/schema/notification.ts index 4e2917ca..0179f3c7 100644 --- a/packages/server/src/db/schema/notification.ts +++ b/packages/server/src/db/schema/notification.ts @@ -270,7 +270,7 @@ export const apiCreateGotify = notificationsSchema export const apiUpdateGotify = apiCreateGotify.partial().extend({ notificationId: z.string().min(1), gotifyId: z.string().min(1), - userId: z.string().optional(), + organizationId: z.string().optional(), }); export const apiTestGotifyConnection = apiCreateGotify diff --git a/packages/server/src/utils/notifications/server-threshold.ts b/packages/server/src/utils/notifications/server-threshold.ts index c606f0ef..2e63ba25 100644 --- a/packages/server/src/utils/notifications/server-threshold.ts +++ b/packages/server/src/utils/notifications/server-threshold.ts @@ -18,7 +18,7 @@ interface ServerThresholdPayload { } export const sendServerThresholdNotifications = async ( - userId: string, + organizationId: string, payload: ServerThresholdPayload, ) => { const date = new Date(payload.Timestamp); @@ -27,7 +27,7 @@ export const sendServerThresholdNotifications = async ( const notificationList = await db.query.notifications.findMany({ where: and( eq(notifications.serverThreshold, true), - eq(notifications.userId, userId), + eq(notifications.organizationId, organizationId), ), with: { email: true,