Search code examples
firebasefirebase-authenticationfirebaseuifirebase-admin

Firebase API-created user can't sign in with email link with disableSignUp status true


  • I need to create users server-side using Firebase Admin.
  • I disallow signups using Firebaseui with disableSignUp status set to true.
  • I wish to use email link sign in only.

When I create the user (in Python) using

auth.create_user(email=email, display_name=name, photo_url=profile_image_url)

a user is created but the user has no providerData and is shown the message:

newuser@example.com is not authorized to view the requested page.

That's unexpected - the Firebaseui documentation says that users can be created through the API and one would expect such users to be able to log in!

When I create the user as above but with a password, they are allowed to log in but they are shown a password prompt.

How can I create a new email user and force email link sign in?


Solution

  • I already have a cloud function to notify users that their account has been created. I added

      var actionCodeSettings = {
        url: 'https://example.com/welcome',
        handleCodeInApp: true,
      };  
    
      const link =  await admin.auth().generateSignInWithEmailLink(user.email, actionCodeSettings);
    

    to the function, and they now get a link to complete their account setup. Landing on '/welcome' opens the firebaseui-auth-container where the message "Confirm your email to complete sign in" is shown. The email is confirmed, and the user is changed to an emailLink user. It's a quite natural flow, almost as if it was designed for that purpose...