Search code examples
firebasereact-nativefirebase-authenticationreact-native-firebase

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.

I would like to support the scenario where users sign-in on mobile, but open the link on their 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:

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:

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
  • Opening the link on PC navigates to the above index.html
  • After confirming the email through the prompt:
    • Login is successful: 'Sign-in successful' in console
    • New user created/visible in Firebase Console

What is still missing:

Mobile app is not notified about the sign-in (specifically, onAuthStateChanged handler is not firing).


Solution

  • Meanwhile I've learned that this is not how Firebase Auth works. 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)
    • In my case: one auth realm = one device

    TL;DR: Passwordless sign-in across devices is not supported out-of-the-box