Spin out config files for each environment

This commit is contained in:
Austin Chen 2022-03-07 18:19:36 -08:00
parent 21180c2ff0
commit deed8426f1
4 changed files with 99 additions and 56 deletions

View File

@ -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 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) { export function isWhitelisted(email?: string) {
switch (ENV) { if (!ENV_CONFIG.whitelistEmail) {
case 'THEOREMONE':
return email && (email.endsWith('@theoremone.co') || isAdmin(email))
case 'PROD':
case 'DEV':
default:
return true return true
} }
return email && (email.endsWith(ENV_CONFIG.whitelistEmail) || isAdmin(email))
} }
// TODO: Before open sourcing, we should turn these into env vars // TODO: Before open sourcing, we should turn these into env vars
export function isAdmin(email: string) { export function isAdmin(email: string) {
const ADMINS = [ return ENV_CONFIG.adminEmails.includes(email)
'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)
} }
export const FIREBASE_CONFIGS = { export const DOMAIN = ENV_CONFIG.domain
PROD: { export const FIREBASE_CONFIG = ENV_CONFIG.firebaseConfig
apiKey: 'AIzaSyDp3J57vLeAZCzxLD-vcPaGIkAmBoGOSYw', export const PROJECT_ID = ENV_CONFIG.firebaseConfig.projectId
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

14
common/envs/dev.ts Normal file
View File

@ -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',
},
}

47
common/envs/prod.ts Normal file
View File

@ -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',
}

19
common/envs/theoremone.ts Normal file
View File

@ -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',
}