mirror of
https://github.com/formbricks/formbricks.git
synced 2026-05-03 03:14:34 -05:00
chore: Auth module revamp (#4335)
Co-authored-by: pandeymangg <anshuman.pandey9999@gmail.com> Co-authored-by: Matthias Nannt <mail@matthiasnannt.com>
This commit is contained in:
committed by
GitHub
parent
7598a16b75
commit
f80d1b32b7
@@ -17,6 +17,7 @@ import { getOrganizationByEnvironmentId } from "@formbricks/lib/organization/ser
|
||||
import type { TLinkSurveyEmailData } from "@formbricks/types/email";
|
||||
import type { TResponse } from "@formbricks/types/responses";
|
||||
import type { TSurvey } from "@formbricks/types/surveys/types";
|
||||
import { TUserEmail, TUserLocale } from "@formbricks/types/user";
|
||||
import type { TWeeklySummaryNotificationResponse } from "@formbricks/types/weekly-summary";
|
||||
import { ForgotPasswordEmail } from "./emails/auth/forgot-password-email";
|
||||
import { PasswordResetNotifyEmail } from "./emails/auth/password-reset-notify-email";
|
||||
@@ -42,12 +43,6 @@ interface SendEmailDataProps {
|
||||
html: string;
|
||||
}
|
||||
|
||||
interface TEmailUser {
|
||||
id: string;
|
||||
email: string;
|
||||
locale: string;
|
||||
}
|
||||
|
||||
const getEmailSubject = (productName: string): string => {
|
||||
return `${productName} User Insights - Last Week by Formbricks`;
|
||||
};
|
||||
@@ -75,26 +70,38 @@ export const sendEmail = async (emailData: SendEmailDataProps): Promise<void> =>
|
||||
await transporter.sendMail({ ...emailDefaults, ...emailData });
|
||||
};
|
||||
|
||||
export const sendVerificationEmail = async (user: TEmailUser): Promise<void> => {
|
||||
const token = createToken(user.id, user.email, {
|
||||
export const sendVerificationEmail = async ({
|
||||
id,
|
||||
email,
|
||||
locale,
|
||||
}: {
|
||||
id: string;
|
||||
email: TUserEmail;
|
||||
locale: TUserLocale;
|
||||
}): Promise<void> => {
|
||||
const token = createToken(id, email, {
|
||||
expiresIn: "1d",
|
||||
});
|
||||
const verifyLink = `${WEBAPP_URL}/auth/verify?token=${encodeURIComponent(token)}`;
|
||||
const verificationRequestLink = `${WEBAPP_URL}/auth/verification-requested?token=${encodeURIComponent(token)}`;
|
||||
const html = await render(VerificationEmail({ verificationRequestLink, verifyLink, locale: user.locale }));
|
||||
const html = await render(VerificationEmail({ verificationRequestLink, verifyLink, locale }));
|
||||
await sendEmail({
|
||||
to: user.email,
|
||||
subject: translateEmailText("verification_email_subject", user.locale),
|
||||
to: email,
|
||||
subject: translateEmailText("verification_email_subject", locale),
|
||||
html,
|
||||
});
|
||||
};
|
||||
|
||||
export const sendForgotPasswordEmail = async (user: TEmailUser, locale: string): Promise<void> => {
|
||||
export const sendForgotPasswordEmail = async (user: {
|
||||
id: string;
|
||||
email: TUserEmail;
|
||||
locale: TUserLocale;
|
||||
}): Promise<void> => {
|
||||
const token = createToken(user.id, user.email, {
|
||||
expiresIn: "1d",
|
||||
});
|
||||
const verifyLink = `${WEBAPP_URL}/auth/forgot-password/reset?token=${encodeURIComponent(token)}`;
|
||||
const html = await render(ForgotPasswordEmail({ verifyLink, locale }));
|
||||
const html = await render(ForgotPasswordEmail({ verifyLink, locale: user.locale }));
|
||||
await sendEmail({
|
||||
to: user.email,
|
||||
subject: "Reset your Formbricks password",
|
||||
@@ -102,7 +109,10 @@ export const sendForgotPasswordEmail = async (user: TEmailUser, locale: string):
|
||||
});
|
||||
};
|
||||
|
||||
export const sendPasswordResetNotifyEmail = async (user: TEmailUser): Promise<void> => {
|
||||
export const sendPasswordResetNotifyEmail = async (user: {
|
||||
email: string;
|
||||
locale: TUserLocale;
|
||||
}): Promise<void> => {
|
||||
const html = await render(PasswordResetNotifyEmail({ locale: user.locale }));
|
||||
await sendEmail({
|
||||
to: user.email,
|
||||
|
||||
Reference in New Issue
Block a user