Skip to content

Commit

Permalink
parse firebase_config env variable in vite.config
Browse files Browse the repository at this point in the history
  • Loading branch information
nwaughachukwuma committed Nov 22, 2024
1 parent a358954 commit 4f8e2d7
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 10 deletions.
3 changes: 1 addition & 2 deletions app/src/env/setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,5 @@ export const env = {
VERSION: process.env.VERSION,
BUILD_TIME: new Date().toString(),
API_BASE_URL: process.env.API_BASE_URL,
IMGPROXY_URL: process.env.IMGPROXY_URL,
FIREBASE_CONFIG: process.env.FIREBASE_CONFIG
IMGPROXY_URL: process.env.IMGPROXY_URL
};
12 changes: 6 additions & 6 deletions app/src/lib/services/firebase/index.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import { initializeApp } from 'firebase/app';
import { initializeApp, getApps } from 'firebase/app';
import { initializeFirestore } from 'firebase/firestore';
import { refs } from './firebase.firestore';
import { browser } from '$app/environment';
import { env } from '@env';
import { initAnalytics } from './firebase.analytics';
import { browser } from '$app/environment';

export const app = initializeApp(env.FIREBASE_CONFIG);
// Initialize Firebase
export const app = getApps()[0] || initializeApp(process.env.FIREBASE_CONFIG);
export const firestore = initializeFirestore(app, {
experimentalAutoDetectLongPolling: browser,
localCache: browser ? { kind: 'persistent' } : void 0
});

export const dbRefs = refs(firestore);

initAnalytics(app);
export const analytics = initAnalytics(app);
export const dbRefs = refs(firestore);
1 change: 1 addition & 0 deletions app/src/routes/chat/+layout.server.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const ssr = false;
3 changes: 1 addition & 2 deletions app/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ export default defineConfig({
include: ['src/**/*.{test,spec}.{js,ts}']
},
define: {
'process.env.USE_EMULATORS': `'${process.env.USE_EMULATORS || false}'`,
'process.env.FIREBASE_CONFIG': `'${process.env.FIREBASE_CONFIG || {}}'`,
'process.env.FIREBASE_CONFIG': process.env.FIREBASE_CONFIG,
...defineEnv()
},
build: {
Expand Down

0 comments on commit 4f8e2d7

Please sign in to comment.