Keep expired invitation hashes so a request for a new link still sends mail.

Clearing the hash made the expired page report success without sending, and made the invite look accepted.
This commit is contained in:
adilallo committed 2026-11-10 15:43:30 -07:00
1 parent b4d0d085d3
commit a8b23bddc2
6 files changed
+15 -48

No files matched your search

+6 -23
View File
@@ -16,15 +16,6 @@ export interface PruneStore {
where: { expiresAt: { lt: Date } };
}) => Promise<{ count: number }>;
};
ruleStakeholder: {
updateMany: (args: {
where: {
inviteTokenHash: { not: null };
inviteExpiresAt: { lt: Date };
};
data: { inviteTokenHash: null; inviteExpiresAt: null };
}) => Promise<{ count: number }>;
};
workshopInquiry: {
deleteMany: (args: {
where: { createdAt: { lt: Date } };
@@ -36,7 +27,6 @@ export interface PruneExpiredResult {
sessions: number;
magicLinkTokens: number;
emailChangeTokens: number;
unusedInviteTokens: number;
workshopInquiries: number;
}
@@ -53,8 +43,12 @@ export async function deleteExpiredWorkshopInquiries(
/**
* Delete expired sessions, login/save-progress tokens (and the draft they
* carry), email-change tokens, unused invitation tokens, and old workshop
* inquiries. Does not delete stakeholder rows or accounts.
* carry), email-change tokens, and old workshop inquiries.
*
* Does not delete stakeholder rows, accounts, or invitation token hashes.
* Verify already rejects an invite once `inviteExpiresAt` has passed. The
* hash is how `/invite/expired` finds that row to send a new link, and a
* null hash is treated as an accepted invite.
*/
export async function pruneExpiredRecords(
db: PruneStore,
@@ -69,23 +63,12 @@ export async function pruneExpiredRecords(
const emailChangeTokens = await db.emailChangeToken.deleteMany({
where: { expiresAt: { lt: now } },
});
const unusedInviteTokens = await db.ruleStakeholder.updateMany({
where: {
inviteTokenHash: { not: null },
inviteExpiresAt: { lt: now },
},
data: {
inviteTokenHash: null,
inviteExpiresAt: null,
},
});
const workshopInquiries = await deleteExpiredWorkshopInquiries(db, now);
return {
sessions: sessions.count,
magicLinkTokens: magicLinkTokens.count,
emailChangeTokens: emailChangeTokens.count,
unusedInviteTokens: unusedInviteTokens.count,
workshopInquiries,
};
}