From deed8426f1e4a887fe7766cf67b2f68c44415b6c Mon Sep 17 00:00:00 2001 From: Austin Chen Date: Mon, 7 Mar 2022 18:19:36 -0800 Subject: [PATCH] Spin out config files for each environment --- common/access.ts | 75 ++++++++++----------------------------- common/envs/dev.ts | 14 ++++++++ common/envs/prod.ts | 47 ++++++++++++++++++++++++ common/envs/theoremone.ts | 19 ++++++++++ 4 files changed, 99 insertions(+), 56 deletions(-) create mode 100644 common/envs/dev.ts create mode 100644 common/envs/prod.ts create mode 100644 common/envs/theoremone.ts diff --git a/common/access.ts b/common/access.ts index 68fddd0f..f828b5c8 100644 --- a/common/access.ts +++ b/common/access.ts @@ -1,66 +1,29 @@ +import { DEV_CONFIG } from './envs/dev' +import { EnvConfig, PROD_CONFIG } from './envs/prod' +import { THEOREMONE_CONFIG } from './envs/theoremone' + const ENV = process.env.NEXT_PUBLIC_FIREBASE_ENV ?? 'PROD' +const CONFIGS = { + PROD: PROD_CONFIG, + DEV: DEV_CONFIG, + THEOREMONE: THEOREMONE_CONFIG, +} +// @ts-ignore +export const ENV_CONFIG: EnvConfig = CONFIGS[ENV] + export function isWhitelisted(email?: string) { - switch (ENV) { - case 'THEOREMONE': - return email && (email.endsWith('@theoremone.co') || isAdmin(email)) - case 'PROD': - case 'DEV': - default: - return true + if (!ENV_CONFIG.whitelistEmail) { + return true } + return email && (email.endsWith(ENV_CONFIG.whitelistEmail) || isAdmin(email)) } // TODO: Before open sourcing, we should turn these into env vars export function isAdmin(email: string) { - const ADMINS = [ - 'akrolsmir@gmail.com', // Austin - 'jahooma@gmail.com', // James - 'taowell@gmail.com', // Stephen - 'manticmarkets@gmail.com', // Manifold - ] - if (ENV === 'THEOREMONE') { - ADMINS.push('david.glidden@theoremone.co') - } - return ADMINS.includes(email) + return ENV_CONFIG.adminEmails.includes(email) } -export const FIREBASE_CONFIGS = { - PROD: { - apiKey: 'AIzaSyDp3J57vLeAZCzxLD-vcPaGIkAmBoGOSYw', - authDomain: 'mantic-markets.firebaseapp.com', - projectId: 'mantic-markets', - storageBucket: 'mantic-markets.appspot.com', - messagingSenderId: '128925704902', - appId: '1:128925704902:web:f61f86944d8ffa2a642dc7', - measurementId: 'G-SSFK1Q138D', - }, - DEV: { - apiKey: 'AIzaSyBoq3rzUa8Ekyo3ZaTnlycQYPRCA26VpOw', - authDomain: 'dev-mantic-markets.firebaseapp.com', - projectId: 'dev-mantic-markets', - storageBucket: 'dev-mantic-markets.appspot.com', - messagingSenderId: '134303100058', - appId: '1:134303100058:web:27f9ea8b83347251f80323', - measurementId: 'G-YJC9E37P37', - }, - THEOREMONE: { - apiKey: 'AIzaSyBSXL6Ys7InNHnCKSy-_E_luhh4Fkj4Z6M', - authDomain: 'theoremone-manifold.firebaseapp.com', - projectId: 'theoremone-manifold', - storageBucket: 'theoremone-manifold.appspot.com', - messagingSenderId: '698012149198', - appId: '1:698012149198:web:b342af75662831aa84b79f', - measurementId: 'G-Y3EZ1WNT6E', - }, -} - -const DOMAINS = { - PROD: 'manifold.markets', - DEV: 'manifold.markets', - THEOREMONE: 'theoremone.manifold.markets', -} -// @ts-ignore -export const DOMAIN = DOMAINS[ENV] -// @ts-ignore -export const PROJECT_ID = FIREBASE_CONFIGS[ENV].projectId +export const DOMAIN = ENV_CONFIG.domain +export const FIREBASE_CONFIG = ENV_CONFIG.firebaseConfig +export const PROJECT_ID = ENV_CONFIG.firebaseConfig.projectId diff --git a/common/envs/dev.ts b/common/envs/dev.ts new file mode 100644 index 00000000..9b82f3c0 --- /dev/null +++ b/common/envs/dev.ts @@ -0,0 +1,14 @@ +import { EnvConfig, PROD_CONFIG } from './prod' + +export const DEV_CONFIG: EnvConfig = { + ...PROD_CONFIG, + firebaseConfig: { + apiKey: 'AIzaSyBoq3rzUa8Ekyo3ZaTnlycQYPRCA26VpOw', + authDomain: 'dev-mantic-markets.firebaseapp.com', + projectId: 'dev-mantic-markets', + storageBucket: 'dev-mantic-markets.appspot.com', + messagingSenderId: '134303100058', + appId: '1:134303100058:web:27f9ea8b83347251f80323', + measurementId: 'G-YJC9E37P37', + }, +} diff --git a/common/envs/prod.ts b/common/envs/prod.ts new file mode 100644 index 00000000..e25c2661 --- /dev/null +++ b/common/envs/prod.ts @@ -0,0 +1,47 @@ +export type EnvConfig = { + domain: string + firebaseConfig: FirebaseConfig + + // Access controls + adminEmails: string[] + whitelistEmail?: string // e.g. '@theoremone.co'. If not provided, all emails are whitelisted + visibility: 'PRIVATE' | 'PUBLIC' + + // Branding + moneyMoniker: string // e.g. 'M$' + faviconPath?: string // Should be a file in /public + navbarLogoPath?: string +} + +type FirebaseConfig = { + apiKey: string + authDomain: string + projectId: string + storageBucket: string + messagingSenderId: string + appId: string + measurementId: string +} + +export const PROD_CONFIG: EnvConfig = { + domain: 'manifold.markets', + firebaseConfig: { + apiKey: 'AIzaSyDp3J57vLeAZCzxLD-vcPaGIkAmBoGOSYw', + authDomain: 'mantic-markets.firebaseapp.com', + projectId: 'mantic-markets', + storageBucket: 'mantic-markets.appspot.com', + messagingSenderId: '128925704902', + appId: '1:128925704902:web:f61f86944d8ffa2a642dc7', + measurementId: 'G-SSFK1Q138D', + }, + adminEmails: [ + 'akrolsmir@gmail.com', // Austin + 'jahooma@gmail.com', // James + 'taowell@gmail.com', // Stephen + 'manticmarkets@gmail.com', // Manifold + ], + moneyMoniker: 'M$', + visibility: 'PUBLIC', + navbarLogoPath: '', + faviconPath: '/favicon.ico', +} diff --git a/common/envs/theoremone.ts b/common/envs/theoremone.ts new file mode 100644 index 00000000..3cd9d0d8 --- /dev/null +++ b/common/envs/theoremone.ts @@ -0,0 +1,19 @@ +import { EnvConfig, PROD_CONFIG } from './prod' + +export const THEOREMONE_CONFIG: EnvConfig = { + domain: 'theoremone.manifold.markets', + firebaseConfig: { + apiKey: 'AIzaSyBSXL6Ys7InNHnCKSy-_E_luhh4Fkj4Z6M', + authDomain: 'theoremone-manifold.firebaseapp.com', + projectId: 'theoremone-manifold', + storageBucket: 'theoremone-manifold.appspot.com', + messagingSenderId: '698012149198', + appId: '1:698012149198:web:b342af75662831aa84b79f', + measurementId: 'G-Y3EZ1WNT6E', + }, + adminEmails: [...PROD_CONFIG.adminEmails, 'david.glidden@theoremone.co'], + whitelistEmail: '@theoremone.co', + moneyMoniker: 'T$', + visibility: 'PRIVATE', + faviconPath: '/theoremone/logo.ico', +}