Skip to content

Instantly share code, notes, and snippets.

@brittanydionigi
Last active July 12, 2018 16:03
Show Gist options
  • Save brittanydionigi/251de632b6cf9c5a92f087a46caf8bbc to your computer and use it in GitHub Desktop.
Save brittanydionigi/251de632b6cf9c5a92f087a46caf8bbc to your computer and use it in GitHub Desktop.
<!doctype html>
<html>
<head>
<title>Firebase Google Auth</title>
<style type="text/css">body,button,html{text-align:center}body,html{margin:50px;font-family:'Helvetica Neue'}button{border:0;background-color:pink;text-transform:uppercase;color:#fff;padding:15px 30px;margin:0 auto}#accountDetails{font-family:'Courier New';border:1px solid #eee;padding:20px;margin:20px auto;overflow-wrap:break-word}</style>
</head>
<body>
<button id="signIn">Sign In</button>
<div id="accountDetails"></div>
<!--
STEP ONE:
Add Firebase scripts from the CDN to your page. You will
only need the firebase-app.js file & the firebase-auth.js file.
HINT: https://firebase.google.com/docs/web/setup
-->
<script type="text/javascript">
function toggleSignIn() {
// STEP THREE:
// Check if there is a currentUser authenticated. If not, register
// a new GoogleAuthProvider and trigger a signInWithPopup.
// Otherwise, trigger a signOut.
// HINT: https://firebase.google.com/docs/auth/web/google-signin
}
function initApp() {
// STEP TWO:
// Add your app config. You will need your app's apiKey and authDomain.
// HINT: The configuration values for your app can be found on the
// authentication page in the top right corner when you click 'WEB SETUP'
var config = {
apiKey: "REPLACE WITH YOUR API KEY",
authDomain: "REPLACE WITH YOUR AUTH DOMAIN",
};
firebase.initializeApp(config);
// STEP FOUR:
// Listen for changes in authentication state through firebase.
// If there is a user, update the button text to say 'Sign Out', and update
// the accountDetails div to display JSON.stringify(user)
// If there is NOT a user, update the button text to say 'Sign In', and update
// the accountDetails div to display 'No user data available'
// HINT: https://firebase.google.com/docs/auth/web/manage-users
// Click handler for sign in/sign out button that calls toggleSignIn
document.getElementById('signIn').addEventListener('click', toggleSignIn, false);
}
window.onload = function() {
initApp();
};
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment