Skip to content

Instantly share code, notes, and snippets.

@mikesparr
Last active October 31, 2023 21:12
Show Gist options
  • Save mikesparr/319af39f87cf5d98dabd7a1bdb7b93dd to your computer and use it in GitHub Desktop.
Save mikesparr/319af39f87cf5d98dabd7a1bdb7b93dd to your computer and use it in GitHub Desktop.
Firebase Auth Phone Provider Test

Firebase Setup

  • created Firebase project
  • created Firebase app
  • copied example code
  • setup node enviroment
# install node
brew install node

# setup firebase
npm install -g firebase-tools
firebase login
firebase init
firebase deploy
  • moved index.html, auth.js, index.css to the /public folder generated by npm
// 1) Create a new firebaseui.auth instance stored to our local variable ui
const ui = new firebaseui.auth.AuthUI(firebase.auth())
// 2) These are our configurations.
const uiConfig = {
callbacks: {
signInSuccessWithAuthResult(authResult, redirectUrl) {
return true
},
uiShown() {
document.getElementById("loader").style.display = "none"
},
},
signInFlow: "popup",
signInSuccessUrl: "signedIn",
signInOptions: [
firebase.auth.EmailAuthProvider.PROVIDER_ID,
firebase.auth.GoogleAuthProvider.PROVIDER_ID,
firebase.auth.PhoneAuthProvider.PROVIDER_ID,
// Additional login options should be listed here
// once they are enabled within the console.
],
}
// 3) Call the 'start' method on our ui class
// including our configuration options.
ui.start("#firebaseui-auth-container", uiConfig)
/*Modals*/
.modal {
display: none;
position: fixed;
z-index: 1;
left: 0;
top: 0;
width: 100%;
height: 100%;
overflow: auto;
background-color: #000000; /*Fallback Color*/
background-color: rgba(0, 0, 0, 0.4);
}
.modal-content {
border-radius: 7px;
background-color: #fefefe;
margin: 12% auto;
padding: 20px;
border: 1px solid #888;
width: 60%;
}
.close {
color: #aaa;
float: right;
font-size: 28px;
font-weight: bold;
}
.close:hover,
.close:focus {
color: black;
text-decoration: none;
cursor: pointer;
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
<title>Firebase Example</title>
</head>
<body>
<div id="firebaseui-auth-container">
<!-- This is where the Login ui will load -->
</div>
<!-- The core Firebase JS SDK is always required and must be listed first -->
<script src="https://www.gstatic.com/firebasejs/6.3.3/firebase-app.js"></script>
<!-- TODO: Add SDKs for Firebase products that you want to use
https://firebase.google.com/docs/web/setup#config-web-app -->
<script src="https://www.gstatic.com/firebasejs/6.3.3/firebase-auth.js"></script>
<script>
// Your web app's Firebase configuration
var firebaseConfig = {
apiKey: "AIzaSyCY6EtoEU84mI8GMS7a3zePTLmmu6p70QE",
authDomain: "mike-colette-login-demo.firebaseapp.com",
projectId: "mike-colette-login-demo",
storageBucket: "mike-colette-login-demo.appspot.com",
messagingSenderId: "639462717819",
appId: "1:639462717819:web:cfb41286660d5977f025de",
measurementId: "G-G7YC3W64WN"
};
// Initialize Firebase
firebase.initializeApp(firebaseConfig);
</script>
<!-- Firebase UI -->
<script src="https://cdn.firebase.com/libs/firebaseui/3.5.2/firebaseui.js"></script>
<link
type="text/css"
rel="stylesheet"
href="https://cdn.firebase.com/libs/firebaseui/3.5.2/firebaseui.css"
/>
<script src="./auth.js"></script>
</body>
</html>
@mikesparr
Copy link
Author

Result

Screenshot 2023-10-31 at 1 50 17 PM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment