Ecommerce Shopify WordPress Discussion

Firebase Authentication API with php

<?php class FirebaseOTPAuthentication { private $firebaseConfig; public function __construct($config) { $this->firebaseConfig = $config; $this->initializeFirebase(); add_shortcode('firebase_otp_authentication', array($this, 'renderHTML')); } private function initializeFirebase() { $firebaseVersion = '8.10.0'; // Adjust the version as needed wp_enqueue_script('firebase-app', "{$firebaseVersion}/firebase-app.js", array(), null, true); wp_enqueue_script('firebase-auth', "{$firebaseVersion}/firebase-auth.js", array('firebase-app'), null, true); wp_add_inline_script('firebase-app', 'var firebaseConfig = ' . json_encode($this->firebaseConfig) . '; firebase.initializeApp(firebaseConfig);', 'after'); } public function renderHTML() { ob_start(); ?> <h1>Firebase OTP Authentication</h1> <input type="text" id="phoneNumber" placeholder="Enter your phone number"> <button onclick="sendOTP()">Send OTP</button> <input type="text" id="verificationCode" placeholder="Enter OTP"> <button onclick="verifyOTP()">Verify OTP</button> <div id="recaptcha-container"></div> <!-- Add this line for Recaptcha container --> <script> var firebaseConfig = <?php echo json_encode($this->firebaseConfig); ?>; function sendOTP() { var phoneNumber = document.getElementById("phoneNumber").value; var appVerifier = new firebase.auth.RecaptchaVerifier("recaptcha-container"); firebase.auth().signInWithPhoneNumber(phoneNumber, appVerifier) .then(function (confirmationResult) { window.confirmationResult = confirmationResult; }) .catch(function (error) { console.error("Error sending OTP: ", error); }); } function verifyOTP() { var verificationCode = document.getElementById("verificationCode").value; confirmationResult.confirm(verificationCode) .then(function (result) { console.log("User signed in: ", result.user); }) .catch(function (error) { console.error("Error verifying OTP: ", error); }); } </script> <?php return ob_get_clean(); } } // Firebase configuration $firebaseConfig = [ "apiKey" => "", "authDomain" => "", "projectId" => "", "storageBucket" => "", "messagingSenderId" => "", "appId" => "" ]; // Instantiate the class $firebaseAuth = new FirebaseOTPAuthentication($firebaseConfig); I am working on custom wordpress plugin... In this, problem is when I use firebase cdn version 8.10.0 then work ok but when I use latest version 10.7.2 or any version other after 8.10.0 then this not work and give error in console Uncaught SyntaxError: Cannot use import statement outside a module (at firebase-auth.js:1:1) Uncaught ReferenceError: firebase is not defined at test2/:386:277 Uncaught SyntaxError: Unexpected token 'export' (at firebase-app.js:2539:1) Please suggest some this version problem or some other problem?
It might be a version problem, however the term version remains merely unspecified in your question and henceforth this analysis may not answer your question yet. The error is indeed a Javascript error, more specifically a SyntaxError with the diagnostic message "Unexpected token 'export'". As it is uncaught, it halts that Javascript process (it stops.) For further analysis on your end and possible solution suggestions that can result from it, please consult the reference question on site: Getting Unexpected Token Export. The most straight forward solution, and in this sense it is a version problem, is that you use the version that works: 8.10.0. As I consider you would not have asked this question if you wouldn't want to use a version higher than 8.10.0 (e.g. 10.7.2 or 9.0.2), you can find more information in another reference question: unexpected token export firebase-app.js:1590 that has an answer with the explanation what changed in version 9 and what a solution is. Perhaps you can already apply the following pattern to the basenames in the path component of the script URLs and it works: firebase-*-compat.js ← firebase-*.js (append -compat before .js)

February 4, 2024

TurboCommerce make the better internet purchasing globaly

Turbo Multi-language Translator

Make the better internet purchasing globaly

Turbosify SEO Speed Booster

5.0 (7) Free plan available
Get better conversions by improving store loading speed Installed

Turbo Multi-language Chat - AI Customer service in one hand

TurboCommerce make the better internet purchasing globaly
Our products

The help you need, when you need it

App by Turbo Engine

3 apps • 5.0 average rating

Turbosify Speed Booster

5.0 (7)
Get better conversions by optimizing shopify store Google page speed Installed

Turbosify Translator for Wordpress Woocommerce

5.0 (74) Free Wordpress Woocommerce Plugin
Translate your wordpress website to multiple language within 1 click, no configuration needed, no No technical required

Grow your business here

Whether you want to sell products down the street or around the world, we have all the tools you need.