-
Notifications
You must be signed in to change notification settings - Fork 0
/
firebaseAdmin.ts
50 lines (45 loc) · 1.09 KB
/
firebaseAdmin.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
/**
* This file is used to initialize the Firebase Admin SDK.
*
* It is used to interact with Firebase services from the server side.
*
* @module firebaseAdmin
*
* @packageDocumentation
*/
import * as admin from 'firebase-admin';
import { getAuth } from 'firebase-admin/auth';
if (admin.apps.length === 0) {
admin.initializeApp({
credential: admin.credential.cert({
projectId: process.env.NEXT_PUBLIC_FIREBASE_PROJECT_ID,
clientEmail: process.env.FIREBASE_CLIENT_EMAIL,
privateKey: process.env.FIREBASE_PRIVATE_KEY?.replace(/\\n/g, '\n'),
}),
});
}
/**
* The Firestore instance.
*
* This is used to interact with the Firestore database.
*
* @example
* ```typescript
* import { db } from "@/firebaseAdmin";
*
* const docRef = db.collection("users").doc("alex");
* ```
*/
const db = admin.firestore();
/**
* The Firebase Admin SDK instance.
*
* This is used to interact with Firebase services from the server side.
*
* @example
* ```typescript
* import { admin } from "@/firebaseAdmin";
* ```
*/
const adminAuth = getAuth();
export { admin, adminAuth, db };