Skip to content

armgit / kaneo

Public Imported from GitHub
0

⚡ Project management that doesn't become the project. Boards, Gantt charts, and GitHub integration. Self-host it or use Kaneo Cloud.

fix(email): localize auth sign-in emails

Tine00a6e633c86
diff --git a/apps/api/src/auth.ts b/apps/api/src/auth.ts
index b5487bf7a..a94088963 100644
--- a/apps/api/src/auth.ts
+++ b/apps/api/src/auth.ts
@@ -72,6 +72,32 @@ if (process.env.AUTH_SECRET && process.env.AUTH_SECRET.length < 32) {
process.exit(1);
}
+async function getUserLocale(email: string) {
+ const [user] = await db
+ .select({ locale: schema.userTable.locale })
+ .from(schema.userTable)
+ .where(eq(schema.userTable.email, email))
+ .limit(1);
+
+ return user?.locale ?? null;
+}
+
+function getLocaleKey(locale?: string | null) {
+ return locale?.toLowerCase().startsWith("de") ? "de" : "en";
+}
+
+function getAuthEmailCopy(locale?: string | null) {
+ return getLocaleKey(locale) === "de"
+ ? {
+ magicLinkSubject: "Anmeldelink fuer Kaneo",
+ otpSubject: "Bestaetigungscode fuer Kaneo",
+ }
+ : {
+ magicLinkSubject: "Login for Kaneo",
+ otpSubject: "Authentication code for Kaneo",
+ };
+}
+
export const auth = betterAuth({
baseURL: baseURLWithoutPath,
trustedOrigins,
@@ -142,8 +168,11 @@ export const auth = betterAuth({
magicLink({
sendMagicLink: async ({ email, url }) => {
try {
- await sendMagicLinkEmail(email, "Login for Kaneo", {
+ const locale = await getUserLocale(email);
+ const copy = getAuthEmailCopy(locale);
+ await sendMagicLinkEmail(email, copy.magicLinkSubject, {
magicLink: url,
+ locale,
});
} catch (error) {
console.error(error);
@@ -153,7 +182,12 @@ export const auth = betterAuth({
emailOTP({
async sendVerificationOTP({ email, otp, type }) {
if (type === "sign-in") {
- await sendOtpEmail(email, "Authentication code for Kaneo", { otp });
+ const locale = await getUserLocale(email);
+ const copy = getAuthEmailCopy(locale);
+ await sendOtpEmail(email, copy.otpSubject, {
+ otp,
+ locale,
+ });
}
},
}),
@@ -210,11 +244,7 @@ export const auth = betterAuth({
},
async sendInvitationEmail(data) {
const inviteLink = `${process.env.KANEO_CLIENT_URL}/invitation/accept/${data.id}`;
- const [invitedUser] = await db
- .select({ locale: schema.userTable.locale })
- .from(schema.userTable)
- .where(eq(schema.userTable.email, data.email))
- .limit(1);
+ const locale = await getUserLocale(data.email);
const result = await sendWorkspaceInvitationEmail(
data.email,
@@ -222,7 +252,7 @@ export const auth = betterAuth({
{
inviterEmail: data.inviter.user.email,
inviterName: data.inviter.user.name,
- locale: invitedUser?.locale ?? null,
+ locale,
workspaceName: data.organization.name,
invitationLink: inviteLink,
to: data.email,
diff --git a/packages/email/src/templates/magic-link.tsx b/packages/email/src/templates/magic-link.tsx
index 7cc79de42..1005b37d7 100644
--- a/packages/email/src/templates/magic-link.tsx
+++ b/packages/email/src/templates/magic-link.tsx
@@ -6,32 +6,59 @@ void React;
export type MagicLinkEmailProps = {
magicLink: string;
+ locale?: string | null;
};
-const MagicLinkEmail = ({ magicLink }: MagicLinkEmailProps) => (
- <EmailShell
- preview="Sign in to Kaneo"
- title="Your secure sign-in link"
- subtitle="Use this link to continue to your Kaneo workspace."
- >
- <Section>
- <Link style={styles.button} href={magicLink}>
- Sign in to Kaneo
- </Link>
- <Text style={styles.paragraph}>
- This link expires in 5 minutes for your security.
- </Text>
- <Text style={styles.muted}>
- If you didn't request this, you can ignore this email.
- </Text>
- <Section style={styles.divider} />
- <Text style={styles.footer}>Kaneo security email</Text>
- </Section>
- </EmailShell>
-);
+const messages = {
+ en: {
+ preview: "Sign in to Kaneo",
+ title: "Your secure sign-in link",
+ subtitle: "Use this link to continue to your Kaneo workspace.",
+ cta: "Sign in to Kaneo",
+ expiry: "This link expires in 5 minutes for your security.",
+ ignore: "If you didn't request this, you can ignore this email.",
+ footer: "Kaneo security email",
+ },
+ de: {
+ preview: "Bei Kaneo anmelden",
+ title: "Dein sicherer Anmeldelink",
+ subtitle:
+ "Verwende diesen Link, um mit deinem Kaneo-Workspace fortzufahren.",
+ cta: "Bei Kaneo anmelden",
+ expiry: "Dieser Link laeuft aus Sicherheitsgruenden in 5 Minuten ab.",
+ ignore:
+ "Wenn du das nicht angefordert hast, kannst du diese E-Mail ignorieren.",
+ footer: "Kaneo Sicherheits-E-Mail",
+ },
+} as const;
+
+const MagicLinkEmail = ({ magicLink, locale }: MagicLinkEmailProps) => {
+ const copy = locale?.toLowerCase().startsWith("de")
+ ? messages.de
+ : messages.en;
+
+ return (
+ <EmailShell
+ preview={copy.preview}
+ title={copy.title}
+ subtitle={copy.subtitle}
+ >
+ <Section>
+ <Link style={styles.button} href={magicLink}>
+ {copy.cta}
+ </Link>
+ <Text style={styles.paragraph}>{copy.expiry}</Text>
+ <Text style={styles.muted}>{copy.ignore}</Text>
+ <Section style={styles.divider} />
+ <Text style={styles.footer}>{copy.footer}</Text>
+ </Section>
+ </EmailShell>
+ );
+};
MagicLinkEmail.PreviewProps = {
magicLink: "https://kaneo.app",
+ locale: "en-US",
} as MagicLinkEmailProps;
export default MagicLinkEmail;
diff --git a/packages/email/src/templates/otp.tsx b/packages/email/src/templates/otp.tsx
index 818f1d669..69167e661 100644
--- a/packages/email/src/templates/otp.tsx
+++ b/packages/email/src/templates/otp.tsx
@@ -6,31 +6,59 @@ void React;
export type OtpEmailProps = {
otp: string;
+ locale?: string | null;
};
-const OtpEmail = ({ otp }: OtpEmailProps) => (
- <EmailShell
- preview="Your Kaneo verification code"
- title="Your verification code"
- subtitle="Enter this one-time code to finish signing in."
- >
- <Section>
- <Text style={styles.paragraph}>
- {otp} is your Kaneo verification code.
- </Text>
- <Text style={styles.code}>{otp}</Text>
- <Text style={styles.paragraph}>This code expires in 15 minutes.</Text>
- <Text style={styles.muted}>
- If you didn't request this, you can ignore this email.
- </Text>
- <Section style={styles.divider} />
- <Text style={styles.footer}>Kaneo security email</Text>
- </Section>
- </EmailShell>
-);
+const messages = {
+ en: {
+ preview: "Your Kaneo verification code",
+ title: "Your verification code",
+ subtitle: "Enter this one-time code to finish signing in.",
+ code: "is your Kaneo verification code.",
+ expiry: "This code expires in 15 minutes.",
+ ignore: "If you didn't request this, you can ignore this email.",
+ footer: "Kaneo security email",
+ },
+ de: {
+ preview: "Dein Kaneo Bestaetigungscode",
+ title: "Dein Bestaetigungscode",
+ subtitle: "Gib diesen Einmalcode ein, um die Anmeldung abzuschliessen.",
+ code: "ist dein Kaneo Bestaetigungscode.",
+ expiry: "Dieser Code laeuft in 15 Minuten ab.",
+ ignore:
+ "Wenn du das nicht angefordert hast, kannst du diese E-Mail ignorieren.",
+ footer: "Kaneo Sicherheits-E-Mail",
+ },
+} as const;
+
+const OtpEmail = ({ otp, locale }: OtpEmailProps) => {
+ const copy = locale?.toLowerCase().startsWith("de")
+ ? messages.de
+ : messages.en;
+
+ return (
+ <EmailShell
+ preview={copy.preview}
+ title={copy.title}
+ subtitle={copy.subtitle}
+ >
+ <Section>
+ <Text style={styles.paragraph}>
+ {otp} {copy.code}
+ </Text>
+ <Text style={styles.code}>{otp}</Text>
+ <Text style={styles.paragraph}>{copy.expiry}</Text>
+ <Text style={styles.muted}>{copy.ignore}</Text>
+ <Section style={styles.divider} />
+ <Text style={styles.footer}>{copy.footer}</Text>
+ </Section>
+ </EmailShell>
+ );
+};
OtpEmail.PreviewProps = {
otp: "123456",
+ locale: "en-US",
} as OtpEmailProps;
export default OtpEmail;