- {(data?.user?.canAccessToAPI || data?.role === "owner") && (
-
- )}
+ {(data?.canAccessToAPI || data?.role === "owner") &&
}
{isCloud &&
}
diff --git a/apps/dokploy/pages/dashboard/settings/ssh-keys.tsx b/apps/dokploy/pages/dashboard/settings/ssh-keys.tsx
index c97df7ba..8c5082e3 100644
--- a/apps/dokploy/pages/dashboard/settings/ssh-keys.tsx
+++ b/apps/dokploy/pages/dashboard/settings/ssh-keys.tsx
@@ -55,7 +55,7 @@ export async function getServerSideProps(
userId: user.id,
});
- if (!userR.canAccessToSSHKeys) {
+ if (!userR?.canAccessToSSHKeys) {
return {
redirect: {
permanent: true,
diff --git a/apps/dokploy/pages/dashboard/swarm.tsx b/apps/dokploy/pages/dashboard/swarm.tsx
index 3b59c47b..c693fd8c 100644
--- a/apps/dokploy/pages/dashboard/swarm.tsx
+++ b/apps/dokploy/pages/dashboard/swarm.tsx
@@ -58,7 +58,7 @@ export async function getServerSideProps(
userId: user.id,
});
- if (!userR.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 8dcd3f08..3153e80d 100644
--- a/apps/dokploy/pages/dashboard/traefik.tsx
+++ b/apps/dokploy/pages/dashboard/traefik.tsx
@@ -58,7 +58,7 @@ export async function getServerSideProps(
userId: user.id,
});
- if (!userR.canAccessToTraefikFiles) {
+ if (!userR?.canAccessToTraefikFiles) {
return {
redirect: {
permanent: true,
diff --git a/apps/dokploy/pages/swagger.tsx b/apps/dokploy/pages/swagger.tsx
index e4a6fac8..3d8cc01d 100644
--- a/apps/dokploy/pages/swagger.tsx
+++ b/apps/dokploy/pages/swagger.tsx
@@ -63,7 +63,7 @@ export async function getServerSideProps(context: GetServerSidePropsContext) {
userId: user.id,
});
- if (!userR.canAccessToAPI) {
+ if (!userR?.canAccessToAPI) {
return {
redirect: {
permanent: true,
diff --git a/apps/dokploy/server/api/routers/project.ts b/apps/dokploy/server/api/routers/project.ts
index 5fc79f43..e3c24e53 100644
--- a/apps/dokploy/server/api/routers/project.ts
+++ b/apps/dokploy/server/api/routers/project.ts
@@ -8,6 +8,7 @@ import {
applications,
compose,
mariadb,
+ member,
mongo,
mysql,
postgres,
@@ -29,8 +30,8 @@ import {
findUserByAuthId,
findUserById,
updateProjectById,
+ findMemberById,
} from "@dokploy/server";
-
export const projectRouter = createTRPCRouter({
create: protectedProcedure
.input(apiCreateProject)
@@ -71,7 +72,10 @@ export const projectRouter = createTRPCRouter({
.input(apiFindOneProject)
.query(async ({ input, ctx }) => {
if (ctx.user.rol === "member") {
- const { accessedServices } = await findUserById(ctx.user.id);
+ const { accessedServices } = await findMemberById(
+ ctx.user.id,
+ ctx.session.activeOrganizationId,
+ );
await checkProjectAccess(ctx.user.id, "access", input.projectId);
@@ -129,8 +133,9 @@ export const projectRouter = createTRPCRouter({
all: protectedProcedure.query(async ({ ctx }) => {
// console.log(ctx.user);
if (ctx.user.rol === "member") {
- const { accessedProjects, accessedServices } = await findUserById(
+ const { accessedProjects, accessedServices } = await findMemberById(
ctx.user.id,
+ ctx.session.activeOrganizationId,
);
if (accessedProjects.length === 0) {
diff --git a/packages/server/src/services/user.ts b/packages/server/src/services/user.ts
index 170af908..9351a003 100644
--- a/packages/server/src/services/user.ts
+++ b/packages/server/src/services/user.ts
@@ -1,7 +1,7 @@
import { db } from "@dokploy/server/db";
-import type { users_temp } from "@dokploy/server/db/schema";
+import { type users_temp, member } from "@dokploy/server/db/schema";
import { TRPCError } from "@trpc/server";
-import { eq } from "drizzle-orm";
+import { and, eq } from "drizzle-orm";
import { findUserById } from "./admin";
export type User = typeof users_temp.$inferSelect;
@@ -191,3 +191,26 @@ export const checkProjectAccess = async (
});
}
};
+
+export const findMemberById = async (
+ userId: string,
+ organizationId: string,
+) => {
+ const result = await db.query.member.findFirst({
+ where: and(
+ eq(member.userId, userId),
+ eq(member.organizationId, organizationId),
+ ),
+ with: {
+ user: true,
+ },
+ });
+
+ if (!result) {
+ throw new TRPCError({
+ code: "UNAUTHORIZED",
+ message: "Permission denied",
+ });
+ }
+ return result;
+};