-
Notifications
You must be signed in to change notification settings - Fork 5
/
firebase.config.ts
47 lines (43 loc) · 1.59 KB
/
firebase.config.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
// Import the functions you need from the SDKs you need
import { FirebaseApp, getApps, initializeApp } from "firebase/app";
import {
Auth,
browserPopupRedirectResolver,
indexedDBLocalPersistence,
initializeAuth,
browserLocalPersistence,
browserSessionPersistence,
getAuth,
connectAuthEmulator,
} from "firebase/auth";
import { Database, connectDatabaseEmulator, getDatabase } from "firebase/database";
// TODO: Add SDKs for Firebase products that you want to use
// https://firebase.google.com/docs/web/setup#available-libraries
// Your web app's Firebase configuration
const firebaseConfig = {
apiKey: process.env.NEXT_PUBLIC_APP_FIREBASE_APIKEY,
authDomain: process.env.NEXT_PUBLIC_APP_FIREBASE_AUTHDOMAIN,
projectId: process.env.NEXT_PUBLIC_APP_FIREBASE_PROJECTID,
storageBucket: process.env.NEXT_PUBLIC_APP_FIREBASE_STORAGEBUCKET,
messagingSenderId: process.env.APP_FIREBASE_MESSAGINGSENDERID,
appId: process.env.NEXT_PUBLIC_APP_FIREBASE_APPID,
databaseURL: process.env.NEXT_PUBLIC_APP_FIREBASE_DATABASEURL,
};
let _app!: FirebaseApp;
let _auth!: Auth;
let _database!: Database;
if (!getApps().length) {
// Initialize Firebase
_app = initializeApp(firebaseConfig, 'hexa-lite');
// Initialize Realtime Database and get a reference to the service
_database = getDatabase(_app);
// Initialize Auth
_auth = getAuth(_app);
// Emulator setup
if (process.env.NEXT_PUBLIC_ENABLE_EMULATORS === 'true') {
connectDatabaseEmulator(_database, 'localhost', 9000);
connectAuthEmulator(_auth, 'http://127.0.0.1:9099');
}
}
export const database = _database;
export const auth = _auth;