diff --git a/.eslintrc b/.eslintrc index b39c1616..85f69afd 100644 --- a/.eslintrc +++ b/.eslintrc @@ -78,6 +78,10 @@ { "pattern": "@Contexts/*", "group": "internal" + }, + { + "pattern": "@Config/*", + "group": "internal" } ] } @@ -94,7 +98,8 @@ ["@Pages", "./src/pages"], ["@HOCs", "./src/HOCs"], ["@Images", "./src/images"], - ["@Contexts", "./src/contexts"] + ["@Contexts", "./src/contexts"], + ["@Config", "./src/config"] ], "extensions": [".js", ".jsx", ".json", ".ts", ".tsx"] }, diff --git a/config-overrides.js b/config-overrides.js index 7eb24347..99daa082 100644 --- a/config-overrides.js +++ b/config-overrides.js @@ -19,5 +19,6 @@ module.exports = override( '@HOCs': path.resolve(__dirname, './src/HOCs'), '@Images': path.resolve(__dirname, './src/images'), '@Contexts': path.resolve(__dirname, './src/contexts'), + '@Config': path.resolve(__dirname, './src/config'), }) ); diff --git a/src/config.ts b/src/config.ts new file mode 100644 index 00000000..4677d170 --- /dev/null +++ b/src/config.ts @@ -0,0 +1,23 @@ +type Config = { + apiKey?: string; + authDomain?: string; + databaseURL?: string; + projectID?: string; + storageBucket?: string; + messagingSenderID?: string; + appID?: string; + apiURL?: string; + nodeEnv?: string; +}; + +export const config: Config = { + apiKey: process.env.REACT_APP_API_KEY, + authDomain: process.env.REACT_APP_AUTH_DOMAIN, + databaseURL: process.env.REACT_APP_DATABASE_URL, + projectID: process.env.REACT_APP_PROJECT_ID, + storageBucket: process.env.REACT_APP_STORAGE_BUCKET, + messagingSenderID: process.env.REACT_APP_MESSAGING_SENDER_ID, + appID: process.env.REACT_APP_APP_ID, + apiURL: process.env.REACT_APP_API_URL, + nodeEnv: process.env.NODE_ENV, +}; diff --git a/src/index.tsx b/src/index.tsx index d0d51f3b..8a8c2464 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -6,17 +6,18 @@ import 'firebase/firestore'; import * as serviceWorker from './serviceWorker'; import App from '@Pages/App'; +import { config } from '@Config'; -const config = { - apiKey: process.env.REACT_APP_API_KEY, - authDomain: process.env.REACT_APP_AUTH_DOMAIN, - databaseURL: process.env.REACT_APP_DATABASE_URL, - projectId: process.env.REACT_APP_PROJECT_ID, - storageBucket: process.env.REACT_APP_STORAGE_BUCKET, - messagingSenderId: process.env.REACT_APP_MESSAGING_SENDER_ID, +const appConfig = { + apiKey: config.apiKey, + authDomain: config.authDomain, + databaseURL: config.databaseURL, + projectId: config.projectID, + storageBucket: config.storageBucket, + messagingSenderId: config.messagingSenderID, }; -firebase.initializeApp(config); +firebase.initializeApp(appConfig); document.body.style.height = '100%'; document.body.style.margin = '0'; diff --git a/src/pages/App/index.tsx b/src/pages/App/index.tsx index 3bade6b6..dfcfaef7 100644 --- a/src/pages/App/index.tsx +++ b/src/pages/App/index.tsx @@ -27,6 +27,7 @@ import { OfficerRoutingPermission, } from '@HOCs/RoutingPermissions'; import ApiConfigStore from '@Services/ApiConfigStore'; +import { config } from '@Config'; function App(): JSX.Element { const [userClaims, setUserClaims] = useState(null); @@ -146,4 +147,4 @@ function App(): JSX.Element { ); } -export default process.env.NODE_ENV === 'development' ? hot(App) : App; +export default config.nodeEnv === 'development' ? hot(App) : App; diff --git a/src/services/ApiConfigStore.ts b/src/services/ApiConfigStore.ts index 14376758..fbe338e1 100644 --- a/src/services/ApiConfigStore.ts +++ b/src/services/ApiConfigStore.ts @@ -2,13 +2,12 @@ import { ConfigurationParameters, Configuration } from './api'; +import { config } from '@Config'; + class ApiConfigStoreClass { private configParams: ConfigurationParameters = { // TODO: load this from a config instead - basePath: - process.env.NODE_ENV === 'development' - ? 'http://localhost:3001' - : 'https://dev-api.hknucsd.com', + basePath: config.apiURL, }; private config: Configuration = new Configuration(this.configParams); diff --git a/src/services/auth.js b/src/services/auth.js index d746c0fb..ade571c7 100644 --- a/src/services/auth.js +++ b/src/services/auth.js @@ -1,10 +1,6 @@ import * as firebase from 'firebase/app'; import 'firebase/auth'; -import SIGNUP_ENDPOINT from '@Constants/endpoints'; - -const SIGN_UP_URL = `${process.env.REACT_APP_API_BASE_URL}${SIGNUP_ENDPOINT}`; - // Auth API const doCreateUserWithEmailAndPassword = (email, password) => { return firebase.auth().createUserWithEmailAndPassword(email, password); @@ -44,19 +40,6 @@ const getCurrentUserClaims = async () => { return tokenResult.claims; }; -const createUserAccountFromSignup = async signupSubmission => { - const response = await fetch(SIGN_UP_URL, { - method: 'POST', - headers: { - Accept: 'application/json', - 'Content-Type': 'application/json', - }, - body: JSON.stringify(signupSubmission), - }); - - return response; -}; - export { doCreateUserWithEmailAndPassword, doSignInWithEmailAndPassword, @@ -65,5 +48,4 @@ export { doSendVerificationEmail, doPasswordUpdate, getCurrentUserClaims, - createUserAccountFromSignup, }; diff --git a/tsconfig.paths.json b/tsconfig.paths.json index e3cc3c97..9b202231 100644 --- a/tsconfig.paths.json +++ b/tsconfig.paths.json @@ -14,7 +14,8 @@ "@HOCs/*": ["src/HOCs/*"], "@Images": ["src/images"], "@Images/*": ["src/images/*"], - "@Contexts": ["src/contexts"] + "@Contexts": ["src/contexts"], + "@Config": ["src/config"] } } }