diff --git a/packages/server/src/lib/auth.ts b/packages/server/src/lib/auth.ts index c05253a13..051e11797 100644 --- a/packages/server/src/lib/auth.ts +++ b/packages/server/src/lib/auth.ts @@ -148,12 +148,17 @@ const { handler, api } = betterAuth({ const xDokployToken = context?.request?.headers?.get("x-dokploy-token"); if (xDokployToken) { - const user = await getUserByToken(xDokployToken); - if (!user) { + const invitation = await getUserByToken(xDokployToken); + if (!invitation) { throw new APIError("BAD_REQUEST", { message: "User not found", }); } + if (_user.email !== invitation.email) { + throw new APIError("BAD_REQUEST", { + message: "Email does not match invitation", + }); + } } else { const isSSORequest = context?.path.includes("/sso"); if (isSSORequest) {