Skip to content

Instantly share code, notes, and snippets.

Last active October 18, 2019 20:18
Show Gist options
  • Save AramRafeq/f03677343f3485d6d957bfa083d0073d to your computer and use it in GitHub Desktop.
Save AramRafeq/f03677343f3485d6d957bfa083d0073d to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html lang="en">
<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 Auth</title>
<h1>Hello WOrld</h1>
<input type="text" id="phoneNo" placeholder="phone number...">
<div id="recaptcha"></div>
<button id="send">Send Sms</button>
<input type="text" id="code" placeholder="enter code here..." style="display:none;">
<button id="getUser" style="display:none;">Get User</button>
<!-- The core Firebase JS SDK is always required and must be listed first -->
<script src=""></script>
<!-- TODO: Add SDKs for Firebase products that you want to use -->
<script src=""></script>
// Your web app's Firebase configuration
var firebaseConfig = {
// your firebase config file goes here
// Initialize Firebase
window.recaptchaVerifier = new firebase.auth.RecaptchaVerifier('recaptcha');
window.recaptchaVerifier.render().then(function(widgetId) {
window.recaptchaWidgetId = widgetId;
var recaptchaResponse = window.grecaptcha.getResponse(window.recaptchaWidgetId);
// using recaptchaResponse you can block user from taking any action untill valid captcha is returneds
var phoneNumber = $("#phoneNo").val();
var appVerifier = window.recaptchaVerifier;
firebase.auth().signInWithPhoneNumber(phoneNumber, appVerifier)
.then(function (confirmationResult) {
// SMS sent. Prompt user to type the code from the message, then sign the
// user in with confirmationResult.confirm(code).
window.confirmationResult = confirmationResult;
$("#code").css("display", "inline");
$("#getUser").css("display", "inline");
}).catch(function (error) {
window.recaptchaVerifier.render().then(function(widgetId) {
const code = $("#code").val();
window.confirmationResult.confirm(code).then(function (result) {
var user = result.user;
console.log(result, user);
}).catch(function (error) {
alert("Error Happend");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment