-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfirebase.js
More file actions
45 lines (40 loc) · 1.39 KB
/
Copy pathfirebase.js
File metadata and controls
45 lines (40 loc) · 1.39 KB
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
// firebase.js — Pathok Ghar Auth
import { initializeApp } from 'https://www.gstatic.com/firebasejs/10.12.0/firebase-app.js';
import { getAuth, GoogleAuthProvider, signInWithPopup, signOut, onAuthStateChanged }
from 'https://www.gstatic.com/firebasejs/10.12.0/firebase-auth.js';
const firebaseConfig = {
apiKey: 'AIzaSyCN0PqjGG78r6IGKJz7D53xhfllqwFhBo0',
authDomain: 'pathokghar.firebaseapp.com',
databaseURL: 'https://pathokghar-default-rtdb.asia-southeast1.firebasedatabase.app',
projectId: 'pathokghar',
storageBucket: 'pathokghar.firebasestorage.app',
messagingSenderId: '367068410598',
appId: '1:367068410598:web:3be0af281acf767a448127',
measurementId: 'G-WFBP0HJMJV',
};
const app = initializeApp(firebaseConfig);
const auth = getAuth(app);
const provider = new GoogleAuthProvider();
// Auth state — layout.html এর callbacks call করে
onAuthStateChanged(auth, user => {
if (user) {
window.onAuthLogin?.(user);
} else {
window.onAuthLogout?.();
}
});
// Global functions — layout.html থেকে call হয়
window.googleLogin = async () => {
try {
await signInWithPopup(auth, provider);
} catch (e) {
console.error('Login error:', e.message);
}
};
window.doLogout = async () => {
try {
await signOut(auth);
} catch (e) {
console.error('Logout error:', e.message);
}
};