Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions contributors.yml
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,7 @@
- pacexy
- pcattori
- penspinner
- penx
- phishy
- plastic041
- princerajroy
Expand Down
39 changes: 32 additions & 7 deletions examples/firebase-auth-firestore/app/server/firebase.server.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,40 @@
import admin from "firebase-admin/app";
import client from "firebase/app";
import {
getApps as getServerApps,
initializeApp as initializeServerApp,
cert as serverCert,
} from "firebase-admin/app";
import {
getApps as getClientApps,
initializeApp as initializeClientApp,
} from "firebase/app";
import { getAuth as getServerAuth } from "firebase-admin/auth";
import { getAuth as getClientAuth } from "firebase/auth";

if (client.getApps().length === 0) {
client.initializeApp(JSON.parse(process.env.CLIENT_CONFIG as string));
if (getClientApps().length === 0) {
if (!process.env.CLIENT_CONFIG) {
throw new Error("Missing CLIENT_CONFIG environment variable");
}
let config;
try {
config = JSON.parse(process.env.CLIENT_CONFIG);
} catch {
throw Error("Invalid CLIENT_CONFIG environment variable");
}
initializeClientApp(config);
}

if (admin.getApps().length === 0) {
admin.initializeApp({
credential: admin.cert(JSON.parse(process.env.SERVICE_ACCOUNT as string)),
if (getServerApps().length === 0) {
if (!process.env.SERVICE_ACCOUNT) {
throw new Error("Missing SERVICE_ACCOUNT environment variable");
}
let config;
try {
config = JSON.parse(process.env.SERVICE_ACCOUNT);
} catch {
throw Error("Invalid SERVICE_ACCOUNT environment variable");
}
initializeServerApp({
credential: serverCert(config),
});
}

Expand Down