Progressive Web App (PWA) in standalone mode OAuth error

◇◆丶佛笑我妖孽 提交于 2019-11-29 07:09:30

Reading Google documentation:

https://firebase.google.com/docs/auth/web/google-signin

Authenticate with Firebase using the Google provider object. You can prompt your users to sign in with their Google Accounts either by opening a pop-up window or by redirecting to the sign-in page. The redirect method is preferred on mobile devices.

So you have 2 options:

  1. firebase.auth().signInWithPopup(provider)
  2. firebase.auth().signInWithRedirect(provider)

The second must be used when you are into a mobile device.

So the question is: How I detect when I running into a mobile device ?

Code must be something like:

  if ( isInMobileDevice) {

   firebase.auth().getRedirectResult().then(function(result) { .... }

  }
  else {

  firebase.auth().signInWithPopup(provider).then(function(result) { .... }
}

Sorry, Im still searching the way to get the correct value (true/false) into "isInMobileDevice"

you can stablish in the manifest of the app "display:standalone" then detect the launch mode like this

function isRunningStandalone() {
    return (window.matchMedia('(display-mode: standalone)').matches);
}
...
if (isRunningStandalone()) {
    /* This code will be executed if app is running standalone */
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!