简体   繁体   English

RN Firebase:在手机上请求无密码登录,在 PC 上打开链接,在手机上登录?

[英]RN Firebase: Request passwordless sign-in on mobile, open link on PC, get signed-in on mobile?

I've successfully set up a passwordless sign-in flow on mobile (using dynamic links ).我已经在移动设备上成功设置了无密码登录流程(使用动态链接)。 It works on iOS and Android, as long as the sign-in link is opened on the same mobile device.只要登录链接在同一移动设备上打开,它就可以在 iOS 和 Android 上运行。

I would like to support the scenario where users sign-in on mobile, but open the link on their PC .我想支持用户在手机上登录,但在他们的 PC 上打开链接的场景。 Is this even possible?这甚至可能吗?

When clicking the link on the PC, I currently see an empty page, with the URL configured in my ActionCodeSettings :单击 PC 上的链接时,我目前看到一个空白页面,在我的ActionCodeSettings中配置了 URL :

const actionCodeSettings: FirebaseAuthTypes.ActionCodeSettings = {
    handleCodeInApp: true,
    url: 'https://the-url-i-see',
    iOS: {
      bundleId: '...',
    },
    android: {
      packageName: '...',
      installApp: true,
    },
  }

Which parts are missing on my end?我的末端缺少哪些部分?

UPDATE更新

I'm one step closer: I created an index.html to be served via https://the-url-i-see :我又近了一步:我创建了一个index.html以通过https://the-url-i-see服务:

if (firebase.auth().isSignInWithEmailLink(window.location.href)) {
  email = window.prompt('Please provide your email for confirmation');
  firebase.auth().signInWithEmailLink(email, window.location.href).then(() => {
    console.log('Sign-in successful')
  }).catch(e => {
    console.error('Sign-in failed', e)
  })
}

What works now:现在有效:

  • Requesting a sign-in on mobile sends an email link请求在移动设备上登录会发送 email 链接
  • Opening the link on PC navigates to the above index.html在 PC 上打开链接导航到上述index.html
  • After confirming the email through the prompt:通过提示确认email后:
    • Login is successful: 'Sign-in successful' in console登录成功:控制台中的“登录成功”
    • New user created/visible in Firebase Console在 Firebase 控制台中创建/可见的新用户

What is still missing:还缺少什么:

Mobile app is not notified about the sign-in (specifically, onAuthStateChanged handler is not firing).移动应用程序不会收到有关登录的通知(具体而言, onAuthStateChanged处理程序未触发)。

Meanwhile I've learned that this is not how Firebase Auth works.同时我了解到这不是 Firebase Auth 的工作方式。 My new understanding, overly simplified:我的新理解,过于简化:

  • A sign-in link is like a ticket登录链接就像一张票
  • The ticket can be used to sign-in once门票可用于签到一次
  • Signing in is specific to one firebase.auth() realm (which will trigger onAuthStateChanged in this realm)登录特定于一个firebase.auth() realm (将在此领域触发onAuthStateChanged
  • In my case: one auth realm = one device在我的情况下:一个身份验证 realm = 一个设备

TL;DR: Passwordless sign-in across devices is not supported out-of-the-box TL;DR:开箱即用不支持跨设备无密码登录

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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