File tree Expand file tree Collapse file tree 3 files changed +19
-8
lines changed Expand file tree Collapse file tree 3 files changed +19
-8
lines changed Original file line number Diff line number Diff line change 7
7
getDashboardPreferences ,
8
8
} from "~/services/dashboardPreferences.server" ;
9
9
export type { User } from "@trigger.dev/database" ;
10
-
10
+ import { assertEmailAllowed } from "~/utils/email" ;
11
11
type FindOrCreateMagicLink = {
12
12
authenticationMethod : "MAGIC_LINK" ;
13
13
email : string ;
@@ -41,9 +41,7 @@ export async function findOrCreateUser(input: FindOrCreateUser): Promise<LoggedI
41
41
export async function findOrCreateMagicLinkUser ( {
42
42
email,
43
43
} : FindOrCreateMagicLink ) : Promise < LoggedInUser > {
44
- if ( env . WHITELISTED_EMAILS && ! new RegExp ( env . WHITELISTED_EMAILS ) . test ( email ) ) {
45
- throw new Error ( "This email is unauthorized" ) ;
46
- }
44
+ assertEmailAllowed ( email ) ;
47
45
48
46
const existingUser = await prisma . user . findFirst ( {
49
47
where : {
@@ -79,9 +77,7 @@ export async function findOrCreateGithubUser({
79
77
authenticationProfile,
80
78
authenticationExtraParams,
81
79
} : FindOrCreateGithub ) : Promise < LoggedInUser > {
82
- if ( env . WHITELISTED_EMAILS && ! new RegExp ( env . WHITELISTED_EMAILS ) . test ( email ) ) {
83
- throw new Error ( "This email is unauthorized" ) ;
84
- }
80
+ assertEmailAllowed ( email ) ;
85
81
86
82
const name = authenticationProfile . _json . name ;
87
83
let avatarUrl : string | undefined = undefined ;
Original file line number Diff line number Diff line change @@ -3,11 +3,11 @@ import { EmailClient, MailTransportOptions } from "emails";
3
3
import type { SendEmailOptions } from "remix-auth-email-link" ;
4
4
import { redirect } from "remix-typedjson" ;
5
5
import { env } from "~/env.server" ;
6
- import type { User } from "~/models/user.server" ;
7
6
import type { AuthUser } from "./authUser" ;
8
7
import { workerQueue } from "./worker.server" ;
9
8
import { logger } from "./logger.server" ;
10
9
import { singleton } from "~/utils/singleton" ;
10
+ import { assertEmailAllowed } from "~/utils/email" ;
11
11
12
12
const client = singleton (
13
13
"email-client" ,
@@ -66,6 +66,8 @@ function buildTransportOptions(alerts?: boolean): MailTransportOptions {
66
66
}
67
67
68
68
export async function sendMagicLinkEmail ( options : SendEmailOptions < AuthUser > ) : Promise < void > {
69
+ assertEmailAllowed ( options . emailAddress ) ;
70
+
69
71
// Auto redirect when in development mode
70
72
if ( env . NODE_ENV === "development" ) {
71
73
throw redirect ( options . magicLink ) ;
Original file line number Diff line number Diff line change
1
+ import { env } from "~/env.server" ;
2
+
3
+ export function assertEmailAllowed ( email : string ) {
4
+ if ( ! env . WHITELISTED_EMAILS ) {
5
+ return ;
6
+ }
7
+
8
+ const regexp = new RegExp ( env . WHITELISTED_EMAILS ) ;
9
+
10
+ if ( ! regexp . test ( email ) ) {
11
+ throw new Error ( "This email is unauthorized" ) ;
12
+ }
13
+ }
You can’t perform that action at this time.
0 commit comments