Merge pull request #4159 from Dokploy/fix/invitation-email-validation

fix: validate invitation email matches signup email
This commit is contained in:
Mauricio Siu
2026-04-05 12:45:00 -06:00
committed by GitHub
+23 -3
View File
@@ -148,10 +148,30 @@ const { handler, api } = betterAuth({
const xDokployToken = const xDokployToken =
context?.request?.headers?.get("x-dokploy-token"); context?.request?.headers?.get("x-dokploy-token");
if (xDokployToken) { if (xDokployToken) {
const user = await getUserByToken(xDokployToken); let invitation: Awaited<ReturnType<typeof getUserByToken>>;
if (!user) { try {
invitation = await getUserByToken(xDokployToken);
} catch {
throw new APIError("BAD_REQUEST", { throw new APIError("BAD_REQUEST", {
message: "User not found", message: "Invalid invitation token",
});
}
if (invitation.isExpired) {
throw new APIError("BAD_REQUEST", {
message: "Invitation has expired",
});
}
if (invitation.status !== "pending") {
throw new APIError("BAD_REQUEST", {
message: "Invitation has already been used",
});
}
if (
_user.email.toLowerCase().trim() !==
invitation.email.toLowerCase().trim()
) {
throw new APIError("BAD_REQUEST", {
message: "Email does not match invitation",
}); });
} }
} else { } else {