@@ -38,31 +38,31 @@ export async function findOrCreateUser(input: FindOrCreateUser): Promise<LoggedI
38
38
}
39
39
}
40
40
41
- export async function findOrCreateMagicLinkUser (
42
- input : FindOrCreateMagicLink
43
- ) : Promise < LoggedInUser > {
44
- if ( env . WHITELISTED_EMAILS && ! new RegExp ( env . WHITELISTED_EMAILS ) . test ( input . email ) ) {
41
+ export async function findOrCreateMagicLinkUser ( {
42
+ email ,
43
+ } : FindOrCreateMagicLink ) : Promise < LoggedInUser > {
44
+ if ( env . WHITELISTED_EMAILS && ! new RegExp ( env . WHITELISTED_EMAILS ) . test ( email ) ) {
45
45
throw new Error ( "This email is unauthorized" ) ;
46
46
}
47
47
48
48
const existingUser = await prisma . user . findFirst ( {
49
49
where : {
50
- email : input . email ,
50
+ email,
51
51
} ,
52
52
} ) ;
53
53
54
54
const adminEmailRegex = env . ADMIN_EMAILS ? new RegExp ( env . ADMIN_EMAILS ) : undefined ;
55
- const makeAdmin = adminEmailRegex ? adminEmailRegex . test ( input . email ) : false ;
55
+ const makeAdmin = adminEmailRegex ? adminEmailRegex . test ( email ) : false ;
56
56
57
57
const user = await prisma . user . upsert ( {
58
58
where : {
59
- email : input . email ,
59
+ email,
60
60
} ,
61
61
update : {
62
- email : input . email ,
62
+ email,
63
63
} ,
64
64
create : {
65
- email : input . email ,
65
+ email,
66
66
authenticationMethod : "MAGIC_LINK" ,
67
67
admin : makeAdmin , // only on create, to prevent automatically removing existing admins
68
68
} ,
@@ -79,6 +79,10 @@ export async function findOrCreateGithubUser({
79
79
authenticationProfile,
80
80
authenticationExtraParams,
81
81
} : FindOrCreateGithub ) : Promise < LoggedInUser > {
82
+ if ( env . WHITELISTED_EMAILS && ! new RegExp ( env . WHITELISTED_EMAILS ) . test ( email ) ) {
83
+ throw new Error ( "This email is unauthorized" ) ;
84
+ }
85
+
82
86
const name = authenticationProfile . _json . name ;
83
87
let avatarUrl : string | undefined = undefined ;
84
88
if ( authenticationProfile . photos [ 0 ] ) {
0 commit comments