Skip to content

Commit

Permalink
feat: support service account object
Browse files Browse the repository at this point in the history
  • Loading branch information
JacobLinCool committed Nov 7, 2024
1 parent dfccce0 commit 2b69a4c
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/lib/server/firebase.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,22 @@
import { env } from '$env/dynamic/private';
import { cert, getApps, initializeApp } from 'firebase-admin/app';
import { cert, getApps, initializeApp, type ServiceAccount } from 'firebase-admin/app';
import { getAuth } from 'firebase-admin/auth';
import { getFirestore } from 'firebase-admin/firestore';

if (!getApps().length) {
let serviceAccountPathOrObject: string | ServiceAccount;
try {
const tmp = JSON.parse(env.GOOGLE_APPLICATION_CREDENTIALS);
if (typeof tmp === 'object') {
serviceAccountPathOrObject = tmp;
} else {
throw new Error();
}
} catch {
serviceAccountPathOrObject = env.GOOGLE_APPLICATION_CREDENTIALS;
}
initializeApp({
credential: cert(env.GOOGLE_APPLICATION_CREDENTIALS)
credential: cert(serviceAccountPathOrObject)
});
}

Expand Down

0 comments on commit 2b69a4c

Please sign in to comment.