Skip to content

Commit dcc4cb1

Browse files
committed
make github auth respect email whitelist
1 parent 41a3bde commit dcc4cb1

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

apps/webapp/app/models/user.server.ts

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -38,31 +38,31 @@ export async function findOrCreateUser(input: FindOrCreateUser): Promise<LoggedI
3838
}
3939
}
4040

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)) {
4545
throw new Error("This email is unauthorized");
4646
}
4747

4848
const existingUser = await prisma.user.findFirst({
4949
where: {
50-
email: input.email,
50+
email,
5151
},
5252
});
5353

5454
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;
5656

5757
const user = await prisma.user.upsert({
5858
where: {
59-
email: input.email,
59+
email,
6060
},
6161
update: {
62-
email: input.email,
62+
email,
6363
},
6464
create: {
65-
email: input.email,
65+
email,
6666
authenticationMethod: "MAGIC_LINK",
6767
admin: makeAdmin, // only on create, to prevent automatically removing existing admins
6868
},
@@ -79,6 +79,10 @@ export async function findOrCreateGithubUser({
7979
authenticationProfile,
8080
authenticationExtraParams,
8181
}: 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+
8286
const name = authenticationProfile._json.name;
8387
let avatarUrl: string | undefined = undefined;
8488
if (authenticationProfile.photos[0]) {

0 commit comments

Comments
 (0)