If you want to transform your Blogger site into a professional web application, having a login system is essential. For those using the Plus UI template, you can easily integrate a 1-click Google Login feature using Firebase Authentication. In this tutorial, I will guide you through the entire process—from setting up your Firebase project to displaying the user's profile on your blog. Let's make your blog smarter today!
Firebase will act as the engine for our authentication system. First, we need to create a project and obtain the API credentials.
firebaseConfig.apiKey, authDomain, projectId, and appId. You will need these for the final script.
Now, we need to modify the Plus UI header so that the profile icon triggers the login process.
CTRL + F and search for data:item == 'Profile'.
<li class='isUser' id='user-auth-area'>
<div id='auth-content'>
<label class='tIc bIc' onclick='googleLogin()' role='button' title='Login'>
<b:include name='profile-icon'/>
</label>
</div>
</li>
This script handles the login logic and profile display. Paste this code right above the closing </body> tag in your theme.
<script src='https://www.gstatic.com/firebasejs/9.6.10/firebase-app-compat.js'/>
<script src='https://www.gstatic.com/firebasejs/9.6.10/firebase-auth-compat.js'/>
<script type='text/javascript'>
//<![CDATA[
const firebaseConfig = {
apiKey: "YOUR_API_KEY",
authDomain: "YOUR_AUTH_DOMAIN",
projectId: "YOUR_PROJECT_ID",
storageBucket: "YOUR_STORAGE_BUCKET",
messagingSenderId: "YOUR_SENDER_ID",
appId: "YOUR_APP_ID"
};
if (!firebase.apps.length) { firebase.initializeApp(firebaseConfig); }
const auth = firebase.auth();
const provider = new firebase.auth.GoogleAuthProvider();
function googleLogin() {
auth.signInWithPopup(provider).then((result) => {
if (result.user) { window.location.assign("/p/dashboard.html"); }
}).catch((error) => {
auth.signInWithRedirect(provider);
});
}
function logout() {
auth.signOut().then(() => { window.location.assign("/"); });
}
auth.onAuthStateChanged((user) => {
const authArea = document.getElementById('auth-content');
if (user && authArea) {
authArea.innerHTML = `
<div onclick='toggleUserMenu()' style='display:flex;align-items:center;cursor:pointer;'>
<img src="${user.photoURL}" class="user-avatar" alt="User" style="width:30px;height:30px;border-radius:50%"/>
<div id="auth-dropdown" class="auth-dropdown">
<span class="auth-name">${user.displayName}</span>
<a href="/p/dashboard.html" class="button" style="width:100%; padding:8px; font-size:12px; border-radius:8px; margin-bottom:8px; display:block; text-decoration:none; text-align:center; color:#fff !important; background:var(--linkB);">Dashboard</a>
<button onclick="logout()" class="button ln" style="width:100%; padding:8px; font-size:12px; border-radius:8px; cursor:pointer;">Logout</button>
</div>
</div>`;
}
});
function toggleUserMenu() {
const menu = document.getElementById('auth-dropdown');
if (menu) menu.classList.toggle('active');
}
window.addEventListener('click', function(e){
const authArea = document.getElementById('user-auth-area');
const dropdown = document.getElementById('auth-dropdown');
if (authArea && dropdown && !authArea.contains(e.target)){
dropdown.classList.remove('active');
}
});
//]]>
</script>
After logging in, users should be redirected to a page that displays their information.
dashboard.html.
<div class='tbd-card' id='dashboard-content' style='padding:40px; text-align:center; min-height: 300px;'>
<div id='user-loading'>Loading profile...</div>
</div>
<script>
auth.onAuthStateChanged((user) => {
const dash = document.getElementById('dashboard-content');
if (user) {
dash.innerHTML = `
<img src="${user.photoURL}" style="width:100px; border-radius:50%; border:3px solid var(--linkB);"/>
<h2>Welcome, ${user.displayName}</h2>
<p>Email: ${user.email}</p>
<button onclick="logout()" class="button ln">Logout</button>`;
} else {
dash.innerHTML = `<h3>Please login to access your dashboard.</h3>`;
}
});
</script>
By following this guide, you have turned your Blogger site into a modern membership platform. The combination of Plus UI's sleek design and Firebase's secure authentication provides an excellent user experience. If you encounter any errors or have questions regarding the implementation, feel free to leave a comment below. Happy Blogging!