-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathfirebase.js
More file actions
56 lines (49 loc) · 1.32 KB
/
firebase.js
File metadata and controls
56 lines (49 loc) · 1.32 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
46
47
48
49
50
51
52
53
54
55
56
import { initializeApp } from "firebase/app";
import {
getAuth,
GithubAuthProvider,
signInWithPopup,
onAuthStateChanged,
getRedirectResult,
} from "firebase/auth";
const firebaseConfig = {
apiKey: "AIzaSyBaXOvbOmPXBfdEnDl2sMLb1jqujGVoZok",
authDomain: "oss-dev-analytics.firebaseapp.com",
projectId: "oss-dev-analytics",
storageBucket: "oss-dev-analytics.firebasestorage.app",
messagingSenderId: "825783735077",
appId: "1:825783735077:web:c8d5a7a1adfd0934ebc0cc",
measurementId: "G-7YFXYWENQH",
};
// Initialize Firebase
const app = initializeApp(firebaseConfig);
const auth = getAuth(app);
// GitHub provider
const provider = new GithubAuthProvider();
getRedirectResult(auth)
.then((result) => {
if (result) {
const user = result.user;
console.log("Redirect login success:", user);
}
})
.catch((error) => {
console.error("Redirect error:", error);
});
export const signInWithGitHub = async () => {
try {
const result = await signInWithPopup(auth, provider);
console.log("User:", result.user);
} catch (error) {
console.error("GitHub Sign-in Error:", error.message);
}
};
// Auth state listener
onAuthStateChanged(auth, (user) => {
if (user) {
console.log("User signed in:", user);
} else {
console.log("No user signed in");
}
});
export { auth, provider };