Agar tum chahte ho ki users Google Account se Login ya Signup karein, to tum Firebase Authentication ka Google Sign-In enable kar sakte ho.
🔥 Steps to Add Google Login in Firebase (Blogger ke liye bhi kaam karega)
1️⃣ Firebase Console me Google Sign-In Enable Karo
- Firebase Console par jao.
- Apne project ko select karo ya naya project banao.
- Authentication → Sign-in method section me jao.
- Google Sign-In select karo aur Enable button daba do.
- Save kar do.
2️⃣ Firebase SDK aur Config Code Blogger me Add Karo
Blogger ya HTML page ke <head>
section me ye Firebase scripts add karo:
<script src="https://www.gstatic.com/firebasejs/9.6.1/firebase-app.js"></script>
<script src="https://www.gstatic.com/firebasejs/9.6.1/firebase-auth.js"></script>
<script>
const firebaseConfig = {
apiKey: "YOUR_API_KEY",
authDomain: "YOUR_PROJECT_ID.firebaseapp.com",
projectId: "YOUR_PROJECT_ID",
storageBucket: "YOUR_PROJECT_ID.appspot.com",
messagingSenderId: "YOUR_MESSAGING_SENDER_ID",
appId: "YOUR_APP_ID"
};
firebase.initializeApp(firebaseConfig);
</script>
3️⃣ Google Login Button Ka Code Add Karo
Blogger me ya kisi HTML file me ye button aur script add karo:
<button onclick="googleSignIn()">Google Se Login Karo</button>
<button onclick="signOut()">Logout</button>
<script>
function googleSignIn() {
var provider = new firebase.auth.GoogleAuthProvider();
firebase.auth().signInWithPopup(provider)
.then((result) => {
var user = result.user;
alert("Welcome, " + user.displayName);
})
.catch((error) => {
alert("Login Failed: " + error.message);
});
}
function signOut() {
firebase.auth().signOut().then(() => {
alert("Logged Out Successfully!");
});
}
</script>
🎯 Features:
✅ Google Account se direct Login/Signup ho jayega
✅ User ka Name, Email, Profile Photo fetch kar sakte ho
✅ Firebase Authentication me automatically user add ho jayega
✅ Blogger ya kisi bhi static website me easily kaam karega
Agar tum full authentication system banana chahte ho, to Google + Email/Password dono support karne ka option bhi hai! 🚀