Skip to content

Instantly share code, notes, and snippets.

@hieptl
Created September 28, 2021 12:53
Show Gist options
  • Save hieptl/37ff5b7e3f0b881f94cdf73fc2bfab53 to your computer and use it in GitHub Desktop.
Save hieptl/37ff5b7e3f0b881f94cdf73fc2bfab53 to your computer and use it in GitHub Desktop.
index.js - Client Side - Header - Tinder Clone
window.addEventListener("DOMContentLoaded", function () {
...
// set header information
const authenticatedUser = JSON.parse(localStorage.getItem("auth"));
if (authenticatedUser) {
...
// show authenticated user on the header.
const headerRight = document.getElementById("header__right");
const userImage = document.getElementById("user__image");
const userName = document.getElementById("user__name");
...
const showHeaderInformation = () => {
if (headerRight && userImage && userName && authenticatedUser && authenticatedUser.uid) {
headerRight.classList.remove("header__right--hide");
userImage.src = authenticatedUser.avatar;
userName.innerHTML = `Hello, ${authenticatedUser.name}`;
}
};
}
...
showHeaderInformation();
...
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment