I've made a sign in code like this:
<!DOCTYPE html>
<html lang="en">
<head>
<title>Gmail Sign In</title>
<script src="https://www.gstatic.com/firebasejs/4.6.2/firebase.js"></script>
<script>
// Initialize Firebase
var config = {
apiKey: "AIzaSyC04no7Ge4ku9xQI3bjJknjhUK9W3UuoiE",
authDomain: "sb-sign.firebaseapp.com",
databaseURL: "https://sb-sign.firebaseio.com",
projectId: "sb-sign",
storageBucket: "sb0!-sign.appspot.com",
messagingSenderId: "431178337718"
};
firebase.initializeApp(config);
window.onload = login();
function login(){
firebase.auth().onAuthStateChanged(newLoginHappend);
function newLoginHappend(user){
if (user){
//user has signed in
app(user);
document.getElementById("SignOutButton").style = "display:block";
}
else{
document.getElementById("SignInButton").style = "display:block";
document.getElementById("ClientName").innerHTML = there! please login.;
}
function app(user){
//user.displayName
//user.email
//user.photoURL
//user.uid
document.getElementById("ClientName").innerHTML = user.displayName;
}
SignIn(){
var provider = new firebase.auth.GoogleAuthProvider();
firebase.auth().signInWithRedirect(provider);
}
}
}
</script>
</head>
<body>
<h1>
Hello, <span id="ClientName"></span>
<button id="SignInButton" style="display:none" onclick='SignIn()'>Sign In</button> <button id="SignOutButton" style="display:none" onclick='firebase.auth().signOut();window.refresh();'>Sign Out</button>
</h1>
</body>
</html>
When body loads, if user is not signed in, then want to show the sign-in button (#SignInButton), hide the sign out button and show a text output saying "hello there! Please login". And when user click over that button, I want show 'em the sign in page. On body load, if the user is already signed in, I wants to show the text, saying "hello ". And also, I want to hide the sign in button and show the sign out button. But when I open this page, I just saw a text "Hello" in the screen. Nothing else shown. Nor sign-in button neither signout button. Please help. Thanks in advance.
Your javascript contain syntax error:
SyntaxError: missing ; before statementfirebase.html:29:60That means that string should be quoted like this:
document.getElementById("ClientName").innerHTML = 'there! please login.';or like this:
document.getElementById("ClientName").innerHTML = "there! please login.";