File tree 3 files changed +9
-2
lines changed 3 files changed +9
-2
lines changed Original file line number Diff line number Diff line change @@ -6,6 +6,7 @@ import { env } from "~/env.server";
6
6
import { sendMagicLinkEmail } from "~/services/email.server" ;
7
7
import { postAuthentication } from "./postAuth.server" ;
8
8
import { logger } from "./logger.server" ;
9
+ import { normalizeEmail } from "~/utils/email" ;
9
10
10
11
let secret = env . MAGIC_LINK_SECRET ;
11
12
if ( ! secret ) throw new Error ( "Missing MAGIC_LINK_SECRET env variable." ) ;
@@ -30,7 +31,7 @@ const emailStrategy = new EmailLinkStrategy(
30
31
31
32
try {
32
33
const { user, isNewUser } = await findOrCreateUser ( {
33
- email,
34
+ email : normalizeEmail ( email ) ,
34
35
authenticationMethod : "MAGIC_LINK" ,
35
36
} ) ;
36
37
Original file line number Diff line number Diff line change @@ -5,6 +5,7 @@ import { findOrCreateUser } from "~/models/user.server";
5
5
import type { AuthUser } from "./authUser" ;
6
6
import { postAuthentication } from "./postAuth.server" ;
7
7
import { logger } from "./logger.server" ;
8
+ import { normalizeEmail } from "~/utils/email" ;
8
9
9
10
export function addGitHubStrategy (
10
11
authenticator : Authenticator < AuthUser > ,
@@ -32,7 +33,7 @@ export function addGitHubStrategy(
32
33
} ) ;
33
34
34
35
const { user, isNewUser } = await findOrCreateUser ( {
35
- email : emails [ 0 ] . value ,
36
+ email : normalizeEmail ( emails [ 0 ] . value ) ,
36
37
authenticationMethod : "GITHUB" ,
37
38
authenticationProfile : profile ,
38
39
authenticationExtraParams : extraParams ,
Original file line number Diff line number Diff line change
1
+ export const normalizeEmail = ( email : string ) : string => {
2
+ const [ localPart , domain ] = email . split ( "@" ) ;
3
+ const normalizedEmail = `${ localPart } @${ domain . toLowerCase ( ) } ` ;
4
+ return normalizedEmail ;
5
+ } ;
You can’t perform that action at this time.
0 commit comments