mirror of
https://github.com/andwati/dokploy.git
synced 2026-11-10 05:55:18 +00:00
Merge pull request #4159 from Dokploy/fix/invitation-email-validation
fix: validate invitation email matches signup email
This commit is contained in:
@@ -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 {
|
||||||
|
|||||||
Reference in New Issue
Block a user