fixes and minor changes for email stuff

This commit is contained in:
Puyodead1 2025-09-05 18:03:59 -04:00
parent 5fafb6d156
commit b8b9b038cf
No known key found for this signature in database
GPG Key ID: A4FA4FEC0DD353FC
2 changed files with 16 additions and 14 deletions

View File

@ -151,7 +151,7 @@ export class SpacebarServer extends Server {
res.sendFile(path.join(PUBLIC_ASSETS_FOLDER, "index.html")), res.sendFile(path.join(PUBLIC_ASSETS_FOLDER, "index.html")),
); );
app.get("/verify", (req, res) => app.get("/verify-email", (req, res) =>
res.sendFile(path.join(PUBLIC_ASSETS_FOLDER, "verify.html")), res.sendFile(path.join(PUBLIC_ASSETS_FOLDER, "verify.html")),
); );

View File

@ -37,9 +37,9 @@ const ASSET_FOLDER_PATH = path.join(
); );
enum MailTypes { enum MailTypes {
verify = "verify", verifyEmail = "verifyEmail",
reset = "reset", resetPassword = "resetPassword",
pwchange = "pwchange", changePassword = "changePassword",
} }
const transporters: { const transporters: {
@ -55,7 +55,7 @@ export const Email: {
transporter: Transporter | null; transporter: Transporter | null;
init: () => Promise<void>; init: () => Promise<void>;
generateLink: ( generateLink: (
type: Omit<MailTypes, "pwchange">, type: Omit<MailTypes, "changePassword">,
id: string, id: string,
email: string, email: string,
) => Promise<string>; ) => Promise<string>;
@ -143,8 +143,10 @@ export const Email: {
const token = (await generateToken(id, email)) as string; const token = (await generateToken(id, email)) as string;
// puyodead1: this is set to api endpoint because the verification page is on the server since no clients have one, and not all 3rd party clients will have one // puyodead1: this is set to api endpoint because the verification page is on the server since no clients have one, and not all 3rd party clients will have one
const instanceUrl = const instanceUrl =
Config.get().api.endpointPublic || "http://localhost:3001"; Config.get().api.endpointPublic?.replace("/api", "") ||
const link = `${instanceUrl}/${type}#token=${token}`; "http://localhost:3001";
const dashedType = type.replace(/([A-Z])/g, "-$1").toLowerCase();
const link = `${instanceUrl}/${dashedType}#token=${token}`;
return link; return link;
}, },
@ -159,9 +161,9 @@ export const Email: {
if (!this.transporter) return; if (!this.transporter) return;
const templateNames: { [key in MailTypes]: string } = { const templateNames: { [key in MailTypes]: string } = {
verify: "verify_email.html", verifyEmail: "verify_email.html",
reset: "password_reset_request.html", resetPassword: "password_reset_request.html",
pwchange: "password_changed.html", changePassword: "password_changed.html",
}; };
const template = await fs.readFile( const template = await fs.readFile(
@ -178,7 +180,7 @@ export const Email: {
template, template,
user, user,
// password change emails don't have links // password change emails don't have links
type != MailTypes.pwchange type != MailTypes.changePassword
? await this.generateLink(type, user.id, email) ? await this.generateLink(type, user.id, email)
: undefined, : undefined,
); );
@ -203,18 +205,18 @@ export const Email: {
* Sends an email to the user with a link to verify their email address * Sends an email to the user with a link to verify their email address
*/ */
sendVerifyEmail: async function (user, email) { sendVerifyEmail: async function (user, email) {
return this.sendMail(MailTypes.verify, user, email); return this.sendMail(MailTypes.verifyEmail, user, email);
}, },
/** /**
* Sends an email to the user with a link to reset their password * Sends an email to the user with a link to reset their password
*/ */
sendResetPassword: async function (user, email) { sendResetPassword: async function (user, email) {
return this.sendMail(MailTypes.reset, user, email); return this.sendMail(MailTypes.resetPassword, user, email);
}, },
/** /**
* Sends an email to the user notifying them that their password has been changed * Sends an email to the user notifying them that their password has been changed
*/ */
sendPasswordChanged: async function (user, email) { sendPasswordChanged: async function (user, email) {
return this.sendMail(MailTypes.pwchange, user, email); return this.sendMail(MailTypes.changePassword, user, email);
}, },
}; };