Cannot connect users

Jason Madi

I'm currently working on a website that has an admin dashboard but I can't log in. Firebase config is copied from the website and Auth is activated with Email and Password. Here my code:

    <script src="https://www.gstatic.com/firebasejs/8.0.1/firebase-auth.js"></script>
    <script>
        // CONFIG FIREBASE
        const firebaseConfig = {
            // Firebase config is copied from the Firebase project
        };
        firebase.initializeApp(firebaseConfig);

        // WORK ON USER
        const myButton = document.getElementById('signing');
        const emailField = document.getElementById('inputEmail');
        const passwordField = document.getElementById('inputPassword');

        myButton.addEventListener(`click`, function() {
            const email = emailField.value;
            const password = passwordField.value;
            
            firebase.auth().signInWithEmailAndPassword(email, password).catch(function(error) {
                const errorCode = error.code;
                const errorMessage = error.message;
                alert('Error : ' + errorCode + ' - ' + errorMessage);
            });

            firebase.auth().onAuthStateChanged(function(user) {
                if (user) {
                    const displayName = user.displayName;
                    const emailU = user.email;
                    alert('Hello ' + displayName + '!');
                    alert('Your mail is ' + emailU);
                } else {
                    alert('Not logged !');
                }
            });
        });
    </script>`

Code of the corresponding form:

<form class="form-signin">
  <img
    class="mb-4"
    src="assets/images/logo.png"
    alt=""
    width="72"
    height="72"
  />
  <h1 class="h3 mb-3 font-weight-normal">Se connecter</h1>
  <label for="inputEmail" class="sr-only">Email address</label>
  <input
    type="email"
    id="inputEmail"
    class="form-control"
    placeholder="Email"
    required
    autofocus
  />
  <label for="inputPassword" class="sr-only">Password</label>
  <input
    type="password"
    id="inputPassword"
    class="form-control"
    placeholder="Mot de passe"
    required
  />
  <button
    id="signing"
    class="btn btn-lg btn-primary btn-block"
    type="submit"
  >
    Se connecter
  </button>
  <p class="mt-5 mb-3 text-muted">Les papilles de Lydie</p>
</form>
Renaud Tarnec

Your problem most probably comes from the fact that your form is submitted before the Firebase signInWithEmailAndPassword() method is triggered.

As seen in the code for the form, you declare your button with a type submit:

<form class="form-signin">
    // ....
    <button id="signing" class="..." type="submit">Se connecter</button>
    // .... 
</form>

You don't want to submit the form, you just want to get the values entered in the fields and pass them to the signInWithEmailAndPassword() method.

So, if you assign the button type to your button, as follows, it should solve your problem, because the form will not be submitted.

<button id="signing" class="..." type="button">Se connecter</button>

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

分類Dev

pymysql cannot connect to mysql

分類Dev

Facebook Connect - get users friends score

分類Dev

Chrome Extension cannot connect to websocket

分類Dev

Type provider cannot connect to localDB

分類Dev

Cannot connect remotely using ssh

分類Dev

Cannot connect VM's in VirtualBox

分類Dev

Fedora 20: Users cannot enter their home directory

分類Dev

Suggestions On How to Handle Facebook Login/Connect On Website for Preexisting Users

分類Dev

Cannot connect to mysql server from java

分類Dev

Cannot connect to mysql server from java

分類Dev

Cannot connect Robomongo using MongoDB docker image

分類Dev

Cannot connect to Hadoop in Docker from Apache Nifi

分類Dev

Android Studio error: cannot connect to daemon

分類Dev

Nestjs/TypeORM Cannot connect to Docker MariaDB

分類Dev

Azure Devops cannot connect to Service Fabric Cluster

分類Dev

Docker compose: services cannot connect to each other

分類Dev

Cannot connect to KAFKA running on Azure App Service

分類Dev

Cannot connect to a local sesame local store

分類Dev

Cannot connect to WiFi network on Windows 8 / 8.1

分類Dev

Cannot connect to SQL Server in Visual Studio

分類Dev

Cannot connect to FTP via Nautilus but FileZilla can

分類Dev

PostgreSQL cannot connect: service definition not found

分類Dev

wkhtmltopdf wkhtmltoimage: cannot connect to X server

分類Dev

PostgreSQL cannot connect: service definition not found

分類Dev

Cannot connect to host even though it is reachable

分類Dev

Entity framework with db mode cannot connect to server

分類Dev

Cannot connect to LAN internet in Ubuntu 20.04

分類Dev

Cannot connect to pop3 or imap with Dovecot

分類Dev

Django with multiple databases and app specific routers, cannot add users in MSSQL

Related 関連記事

  1. 1

    pymysql cannot connect to mysql

  2. 2

    Facebook Connect - get users friends score

  3. 3

    Chrome Extension cannot connect to websocket

  4. 4

    Type provider cannot connect to localDB

  5. 5

    Cannot connect remotely using ssh

  6. 6

    Cannot connect VM's in VirtualBox

  7. 7

    Fedora 20: Users cannot enter their home directory

  8. 8

    Suggestions On How to Handle Facebook Login/Connect On Website for Preexisting Users

  9. 9

    Cannot connect to mysql server from java

  10. 10

    Cannot connect to mysql server from java

  11. 11

    Cannot connect Robomongo using MongoDB docker image

  12. 12

    Cannot connect to Hadoop in Docker from Apache Nifi

  13. 13

    Android Studio error: cannot connect to daemon

  14. 14

    Nestjs/TypeORM Cannot connect to Docker MariaDB

  15. 15

    Azure Devops cannot connect to Service Fabric Cluster

  16. 16

    Docker compose: services cannot connect to each other

  17. 17

    Cannot connect to KAFKA running on Azure App Service

  18. 18

    Cannot connect to a local sesame local store

  19. 19

    Cannot connect to WiFi network on Windows 8 / 8.1

  20. 20

    Cannot connect to SQL Server in Visual Studio

  21. 21

    Cannot connect to FTP via Nautilus but FileZilla can

  22. 22

    PostgreSQL cannot connect: service definition not found

  23. 23

    wkhtmltopdf wkhtmltoimage: cannot connect to X server

  24. 24

    PostgreSQL cannot connect: service definition not found

  25. 25

    Cannot connect to host even though it is reachable

  26. 26

    Entity framework with db mode cannot connect to server

  27. 27

    Cannot connect to LAN internet in Ubuntu 20.04

  28. 28

    Cannot connect to pop3 or imap with Dovecot

  29. 29

    Django with multiple databases and app specific routers, cannot add users in MSSQL

ホットタグ

アーカイブ