简体   繁体   中英

Firebase Web Auth Doesn't Work On Mobile Devices?

I was planning to use Firebase's provider authentication for my webapp, but it seems that it doesn't work on mobile devices. the site is live here:

https://cypher.city

Then when you click this button: 在此处输入图片说明

a popup will appear. And when you click this button: 在此处输入图片说明

then it should go to a google provider authentication flow.

My code for it looks like this:

var provider = new firebase.auth.GoogleAuthProvider();
  firebase.auth().signInWithRedirect(provider).then((result) => {
    // console.log('@$ signin wiht google worked!' + e +', user is: ' + firebase.auth().currentUser.uid);
    console.log('@$ signin wiht google worked!' + result.user);

  }).catch((e) => {
    console.log('@$ signin wiht google failed!' + e);

    firebase.auth().signInAnonymously().then((user) => {
      console.log('@$ signed in anonymously againQ ' + user.uid);
      // console.log('@$ and firebase knows it: ' + firebase.auth().currentUser.uid);
    }).catch((e) => {
      console.log('@$ signed in anonymously failed ' + e);

    })

  })

The problem is that while this works great on desktop it doesn't work at all on mobile devices. I have tried both "signInWithRedirect" and "signInWithPopup", but when I call these methods on my Huawei Honor phone nothing happens (in any browser).

Am I doing something wrong here or does Firebase web authentication just not work on mobile?

This is slightly embarrassing, but it might help someone else. The real issue turned out not to have anything to do with mobile devices, but actually that I was using a custom domain and had forgotten to add it in the auth section on the console. When I tested the production app with chrome dev tools open I could see this error in the console: 在此处输入图片说明

Adding my custom domain in this section of the firebase console worked: 在此处输入图片说明

Some time ago I was trying something similar and for a long time I moved away from this type of login because at the development stage it didn't work for me.

And it was precisely for that reason, because in rea in the development stage I entered my server through an address type 192.157.2.3:3000

try with signInWithPopup and with signInWithRedirect and it didn't work for me

The error is that the request to come from 192.157.2.3:3000 was not supported by firebase, a problem that is simply solved already in production with "firebase deploy".

Here is an example even though Angular is the same

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM