Whitelist admins and new users by email

This commit is contained in:
Austin Chen 2022-02-24 01:42:23 -08:00
parent b4f979ad80
commit a334decd1c
3 changed files with 22 additions and 8 deletions

14
common/access.ts Normal file
View File

@ -0,0 +1,14 @@
export function isWhitelisted(email?: string) {
return true
// e.g. return email.endsWith('@theoremone.co') || isAdmin(email)
}
export function isAdmin(email: string) {
const ADMINS = [
'akrolsmir@gmail.com', // Austin
'jahooma@gmail.com', // James
'taowell@gmail.com', // Stephen
'manticmarkets@gmail.com', // Manifold
]
return ADMINS.includes(email)
}

View File

@ -14,6 +14,7 @@ import {
cleanUsername,
} from '../../common/util/clean-username'
import { sendWelcomeEmail } from './emails'
import { isWhitelisted } from '../../common/access'
export const createUser = functions
.runWith({ minInstances: 1 })
@ -32,6 +33,9 @@ export const createUser = functions
const fbUser = await admin.auth().getUser(userId)
const email = fbUser.email
if (!isWhitelisted(email)) {
return { status: 'error', message: `${email} is not whitelisted` }
}
const emailName = email?.replace(/@.*$/, '')
const rawName = fbUser.displayName || emailName || 'User' + randomString(4)

View File

@ -1,12 +1,8 @@
import { useUser } from './use-user'
import { isAdmin } from '../../common/access'
import { usePrivateUser, useUser } from './use-user'
export const useAdmin = () => {
const user = useUser()
const adminIds = [
'igi2zGXsfxYPgB0DJTXVJVmwCOr2', // Austin
'5LZ4LgYuySdL1huCWe7bti02ghx2', // James
'tlmGNz9kjXc2EteizMORes4qvWl2', // Stephen
'IPTOzEqrpkWmEzh6hwvAyY9PqFb2', // Manifold
]
return adminIds.includes(user?.id || '')
const privateUser = usePrivateUser(user?.id)
return isAdmin(privateUser?.email || '')
}