firebase / firebaseui-web

FirebaseUI is an open-source JavaScript library for Web that provides simple, customizable UI bindings on top of Firebase SDKs to eliminate boilerplate code and promote best practices.
https://firebase.google.com/
Apache License 2.0
4.58k stars 1.06k forks source link

ERROR: No Firebase App '[DEFAULT]' has been created. Using Firebae UI CDN #980

Closed tuberelevant2 closed 1 year ago

tuberelevant2 commented 2 years ago

I'm new to JS. I'm using CDN (

Welcome to My Awesome App

`

I am getting the analytics in my Firebase dashboard. But it says app is not defined. I tried console.log(app) and found that it works just below cont declaration but doesn't work in the line var ui = new firebaseui.auth.AuthUI(firebase.auth()); It shows error when it's reading auth() I hope you just have to copy/paste this code to replicate the issue. Thanks in advance.

Jerit3787 commented 2 years ago

Hi, I noticed that you forgot to include the firebase-auth library which results auth object not being init.

Please refer to the Firebase Documentation about the Firebase Authentication.

Here are the changes I've made to the code you've provided above.

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Sample FirebaseUI App</title>
    <script src="https://www.gstatic.com/firebasejs/9.1.3/firebase-app-compat.js"></script>
    <script src="https://www.gstatic.com/firebasejs/9.1.3/firebase-auth-compat.js"></script> // ADD THIS
    <script src="https://www.gstatic.com/firebasejs/ui/6.0.1/firebase-ui-auth.js"></script>
    <link type="text/css" rel="stylesheet" href="https://www.gstatic.com/firebasejs/ui/6.0.1/firebase-ui-auth.css" />
</head>

<body>
    <div id="firebaseui-auth-container"></div>
    <script type="module">
        // Import the functions you need from the SDKs you need 
        import { initializeApp } from "https://www.gstatic.com/firebasejs/9.12.1/firebase-app.js"; 
        import { getAuth } from "https://www.gstatic.com/firebasejs/9.12.1/firebase-auth.js" // ADD THIS
        import { getAnalytics } from "https://www.gstatic.com/firebasejs/9.12.1/firebase-analytics.js";
        // TODO:Add SDKs for Firebase products that you want to use 
        // https://firebase.google.com/docs/web/setup#available-libraries 

        // Your web app's Firebase configuration 
        // For Firebase JS SDK v7.20.0 and later, measurementId is optional const firebaseConfig
        var firebaseConfig = {
            apiKey: "xxx",
            authDomain: "xxx",
            databaseURL: "xxx",
            projectId: "xxx",
            storageBucket: "xxx",
            messagingSenderId: "xxx",
            appId: "xxx",
            measurementId: "xxx"
        };

        // Initialize Firebase 
        const app = initializeApp(firebaseConfig); 
        const auth = getAuth(app) // ADD THIS
        const analytics = getAnalytics(app);

        // FirebaseUI config.
        var uiConfig = {
            signInSuccessUrl: 'https://www.syllabuzz.in/',
            // tosUrl and privacyPolicyUrl accept either url string or a callback
            // function.
            // Terms of service url/callback.
            tosUrl: 'https://www.syllabuzz.in/',
            // Privacy policy url/callback.
            privacyPolicyUrl: function() {
                window.location.assign('https://www.syllabuzz.in/');
            }
        };
        // Initialize the FirebaseUI Widget using Firebase.
         var ui = new firebaseui.auth.AuthUI(auth); // CHANGE THIS
            // The start method will wait until the DOM is loaded.
            ui.start('#firebaseui-auth-container', {
                signInOptions: [
                        firebase.auth.PhoneAuthProvider.PROVIDER_ID
                ],
                // Other config options...
            })  
    </script>
</body>

</html>

Please do note PhoneAuthProvider still having issue when using Firebase UI. Please try refrain using it. You will see error showing in your debugger's console.

image

This issue won't be solvable until the Firebase team updates the library to support v9 Modular