Skip to content

Commit

Permalink
Divide Firebase configuration values to the new file to avoid the tes…
Browse files Browse the repository at this point in the history
…t failure of the Firebase.ts file.
  • Loading branch information
yoichiro committed May 30, 2024
1 parent 15cd9a0 commit 5b78968
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 10 deletions.
18 changes: 9 additions & 9 deletions src/services/provider/Firebase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,14 @@ import { IDeviceInformation } from '../hid/Hid';
import * as crypto from 'crypto';
import { IBootloaderType } from '../firmware/Types';

const config = {
apiKey: import.meta.env.REACT_APP_FIREBASE_API_KEY,
authDomain: import.meta.env.REACT_APP_FIREBASE_AUTH_DOMAIN,
projectId: import.meta.env.REACT_APP_FIREBASE_PROJECT_ID,
storageBucket: import.meta.env.REACT_APP_FIREBASE_STORAGE_BUCKET,
messagingSenderId: import.meta.env.REACT_APP_FIREBASE_MESSAGE_SENDER_ID,
appId: import.meta.env.REACT_APP_FIREBASE_APP_ID,
measurementId: import.meta.env.REACT_APP_FIREBASE_MEASUREMENT_ID,
export type IFirebaseConfiguration = {
apiKey: string;
authDomain: string;
projectId: string;
storageBucket: string;
messagingSenderId: string;
appId: string;
measurementId: string;
};

const FUNCTIONS_REGION = 'asia-northeast1';
Expand All @@ -71,7 +71,7 @@ export class FirebaseProvider implements IStorage, IAuth {
private functions: firebase.functions.Functions;
private unsubscribeAuthStateChanged?: firebase.Unsubscribe;

constructor() {
constructor(config: IFirebaseConfiguration) {
firebase.initializeApp(config);
firebase.analytics();
const app = firebase.app();
Expand Down
11 changes: 11 additions & 0 deletions src/services/provider/FirebaseConfiguration.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { IFirebaseConfiguration } from './Firebase';

export const firebaseConfiguration: IFirebaseConfiguration = {
apiKey: import.meta.env.REACT_APP_FIREBASE_API_KEY,
authDomain: import.meta.env.REACT_APP_FIREBASE_AUTH_DOMAIN,
projectId: import.meta.env.REACT_APP_FIREBASE_PROJECT_ID,
storageBucket: import.meta.env.REACT_APP_FIREBASE_STORAGE_BUCKET,
messagingSenderId: import.meta.env.REACT_APP_FIREBASE_MESSAGE_SENDER_ID,
appId: import.meta.env.REACT_APP_FIREBASE_APP_ID,
measurementId: import.meta.env.REACT_APP_FIREBASE_MEASUREMENT_ID,
};
3 changes: 2 additions & 1 deletion src/store/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import { IFirmwareWriter } from '../services/firmware/FirmwareWriter';
import { FirmwareWriterWebApiImpl } from '../services/firmware/FirmwareWriterWebApiImpl';
import { IBootloaderType } from '../services/firmware/Types';
import { getLocalAuthenticationUid } from '../utils/AuthUtils';
import { firebaseConfiguration } from '../services/provider/FirebaseConfiguration';

export type ISetupPhase =
| 'init'
Expand Down Expand Up @@ -488,7 +489,7 @@ export type RootState = {

let firebaseProvider;
try {
firebaseProvider = new FirebaseProvider();
firebaseProvider = new FirebaseProvider(firebaseConfiguration);
} catch (cause) {
if (import.meta.env.NODE_ENV === 'production') {
throw cause;
Expand Down

0 comments on commit 5b78968

Please sign in to comment.