fix: enhance invitation validation in authentication logic

- Updated the authentication process to check if the email of the user matches the email associated with the invitation token.
- Improved error handling for cases where the user is not found or the email does not match the invitation.
This commit is contained in:
Mauricio Siu
2026-04-05 12:35:23 -06:00
parent 24b56c868d
commit 17393af717

View File

@@ -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) {