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 77 getDashboardPreferences ,
88} from "~/services/dashboardPreferences.server" ;
99export type { User } from "@trigger.dev/database" ;
10-
10+ import { assertEmailAllowed } from "~/utils/email" ;
1111type FindOrCreateMagicLink = {
1212 authenticationMethod : "MAGIC_LINK" ;
1313 email : string ;
@@ -41,9 +41,7 @@ export async function findOrCreateUser(input: FindOrCreateUser): Promise<LoggedI
4141export async function findOrCreateMagicLinkUser ( {
4242 email,
4343} : 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 ) ;
4745
4846 const existingUser = await prisma . user . findFirst ( {
4947 where : {
@@ -79,9 +77,7 @@ export async function findOrCreateGithubUser({
7977 authenticationProfile,
8078 authenticationExtraParams,
8179} : 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 ) ;
8581
8682 const name = authenticationProfile . _json . name ;
8783 let avatarUrl : string | undefined = undefined ;
Original file line number Diff line number Diff line change @@ -3,11 +3,11 @@ import { EmailClient, MailTransportOptions } from "emails";
33import type { SendEmailOptions } from "remix-auth-email-link" ;
44import { redirect } from "remix-typedjson" ;
55import { env } from "~/env.server" ;
6- import type { User } from "~/models/user.server" ;
76import type { AuthUser } from "./authUser" ;
87import { workerQueue } from "./worker.server" ;
98import { logger } from "./logger.server" ;
109import { singleton } from "~/utils/singleton" ;
10+ import { assertEmailAllowed } from "~/utils/email" ;
1111
1212const client = singleton (
1313 "email-client" ,
@@ -66,6 +66,8 @@ function buildTransportOptions(alerts?: boolean): MailTransportOptions {
6666}
6767
6868export async function sendMagicLinkEmail ( options : SendEmailOptions < AuthUser > ) : Promise < void > {
69+ assertEmailAllowed ( options . emailAddress ) ;
70+
6971 // Auto redirect when in development mode
7072 if ( env . NODE_ENV === "development" ) {
7173 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