Skip to content

Commit

Permalink
Update the Next JS configuration file to set the FIREBASE_CONFIG envi…
Browse files Browse the repository at this point in the history
…ronment variable (codeforbtv#45)
  • Loading branch information
NathanWEdwards authored Feb 25, 2024
1 parent ca11aca commit 0cbdac2
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 5 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,11 @@ If you have performed the above step, the following step should not be necessary
firebase login
```

Set the `NEXT_PUBLIC_FIREBASE_CONFIG` environment variable. For more details about what is in a Firebase config, visit [Understand Firebase projects  |  Firebase Documentation (google.com)](https://firebase.google.com/docs/projects/learn-more#config-files-objects):
Set the `FIREBASE_CONFIG` environment variable. For more details about what is in a Firebase config, visit [Understand Firebase projects  |  Firebase Documentation (google.com)](https://firebase.google.com/docs/projects/learn-more#config-files-objects):


```
export NEXT_PUBLIC_FIREBASE_CONFIG="{ \
export FIREBASE_CONFIG="{ \
\"apiKey\": \"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\", \
\"authDomain\": \"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\", \
\"projectId\": \"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\", \
Expand All @@ -77,7 +77,7 @@ export NEXT_PUBLIC_FIREBASE_CONFIG="{ \
}"
```

or, `export NEXT_PUBLIC_FIREBASE_CONFIG="$(cat <path_to_Firebace_JSON_configuration_file)"`.
or, `export FIREBASE_CONFIG="$(cat <path_to_Firebace_JSON_configuration_file)"`.

#### Configuration File Dependencies

Expand Down
2 changes: 1 addition & 1 deletion functions/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ type Event = {
modifiedAt: string;
};

const firebaseConfig = JSON.parse(process.env.NEXT_PUBLIC_FIREBASE_CONFIG ?? process.env.FIREBASE_CONFIG ?? '{}');
const firebaseConfig = JSON.parse(process.env.FIREBASE_CONFIG ?? '{}');

const app: App = admin.initializeApp({
credential: applicationDefault(),
Expand Down
6 changes: 6 additions & 0 deletions next.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@

const FIREBASE_CONFIG = process.env.FIREBASE_CONFIG;

/** @type {import('next').NextConfig} */
const nextConfig = {
env: {
FIREBASE_CONFIG
},
experimental: {
serverActions: true
}
Expand Down
2 changes: 1 addition & 1 deletion src/api/firebase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
} from 'firebase/auth';
import { AccountInformation, UserBody } from '@/types/post-data';

const firebaseConfig = JSON.parse(process.env.NEXT_PUBLIC_FIREBASE_CONFIG ?? '{}');
const firebaseConfig = JSON.parse(process.env.FIREBASE_CONFIG ?? '{}');

export const app: FirebaseApp = initializeApp(firebaseConfig);
export const db: Firestore = initDb();
Expand Down

0 comments on commit 0cbdac2

Please sign in to comment.