Add document unsubscribe link in email footer (#5762)

This commit is contained in:
Tom Moor
2023-09-03 19:04:28 -04:00
committed by GitHub
parent 0261e0712c
commit d7c331532d
24 changed files with 347 additions and 161 deletions

View File

@@ -0,0 +1,29 @@
import crypto from "crypto";
import env from "@server/env";
/**
* Helper class for working with subscription settings
*/
export default class SubscriptionHelper {
/**
* Get the unsubscribe URL for a user and document. This url allows the user
* to unsubscribe from a specific document without being signed in, for one-click
* links in emails.
*
* @param userId The user ID to unsubscribe
* @param documentId The document ID to unsubscribe from
* @returns The unsubscribe URL
*/
public static unsubscribeUrl(userId: string, documentId: string) {
return `${env.URL}/api/subscriptions.delete?token=${this.unsubscribeToken(
userId,
documentId
)}&userId=${userId}&documentId=${documentId}`;
}
public static unsubscribeToken(userId: string, documentId: string) {
const hash = crypto.createHash("sha256");
hash.update(`${userId}-${env.SECRET_KEY}-${documentId}`);
return hash.digest("hex");
}
}