Skip to content

Commit 78cf23e

Browse files
committed
Initialize firebase-admin
1 parent a0bfa16 commit 78cf23e

File tree

4 files changed

+787
-17
lines changed

4 files changed

+787
-17
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,4 @@ yarn-error.log*
3232

3333
# vercel
3434
.vercel
35+
.env

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
"bcryptjs": "^2.4.3",
1515
"classnames": "^2.3.1",
1616
"firebase": "^9.2.0",
17+
"firebase-admin": "^10.0.0",
1718
"formik": "^2.2.9",
1819
"framer-motion": "^4.1.17",
1920
"js-cookie": "^3.0.1",

src/lib/firebase-admin.ts

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import admin from 'firebase-admin'
2+
3+
export default function getDb() {
4+
try {
5+
return admin.firestore()
6+
} catch {
7+
admin.initializeApp({
8+
credential: admin.credential.cert({
9+
projectId: process.env.FIREBASE_PROJECT_ID,
10+
clientEmail: process.env.FIREBASE_CLIENT_EMAIL,
11+
privateKey: process.env.FIREBASE_PRIVATE_KEY?.replace(/\\n/gm, '\n'),
12+
}),
13+
databaseURL: 'https://tocpc-prod-2021.firebaseio.com',
14+
})
15+
return admin.firestore()
16+
}
17+
}

0 commit comments

Comments
 (0)