Skip to content

Commit fd43645

Browse files
committed
fix: normalize email case to prevent duplicate accounts
1 parent 9882d66 commit fd43645

File tree

3 files changed

+9
-2
lines changed

3 files changed

+9
-2
lines changed

apps/webapp/app/services/emailAuth.server.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { env } from "~/env.server";
66
import { sendMagicLinkEmail } from "~/services/email.server";
77
import { postAuthentication } from "./postAuth.server";
88
import { logger } from "./logger.server";
9+
import { normalizeEmail } from "~/utils/email";
910

1011
let secret = env.MAGIC_LINK_SECRET;
1112
if (!secret) throw new Error("Missing MAGIC_LINK_SECRET env variable.");
@@ -30,7 +31,7 @@ const emailStrategy = new EmailLinkStrategy(
3031

3132
try {
3233
const { user, isNewUser } = await findOrCreateUser({
33-
email,
34+
email: normalizeEmail(email),
3435
authenticationMethod: "MAGIC_LINK",
3536
});
3637

apps/webapp/app/services/gitHubAuth.server.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { findOrCreateUser } from "~/models/user.server";
55
import type { AuthUser } from "./authUser";
66
import { postAuthentication } from "./postAuth.server";
77
import { logger } from "./logger.server";
8+
import { normalizeEmail } from "~/utils/email";
89

910
export function addGitHubStrategy(
1011
authenticator: Authenticator<AuthUser>,
@@ -32,7 +33,7 @@ export function addGitHubStrategy(
3233
});
3334

3435
const { user, isNewUser } = await findOrCreateUser({
35-
email: emails[0].value,
36+
email: normalizeEmail(emails[0].value),
3637
authenticationMethod: "GITHUB",
3738
authenticationProfile: profile,
3839
authenticationExtraParams: extraParams,

apps/webapp/app/utils/email.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
export const normalizeEmail = (email: string): string => {
2+
const [localPart, domain] = email.split("@");
3+
const normalizedEmail = `${localPart}@${domain.toLowerCase()}`;
4+
return normalizedEmail;
5+
};

0 commit comments

Comments
 (0)