firebaseui-web icon indicating copy to clipboard operation
firebaseui-web copied to clipboard

[Feature Request] Support a pre-filled email address

Open dmjones opened this issue 6 years ago • 10 comments

Is your feature request related to a problem? Please describe.

In my landing page, I have a simple form where people can enter their email address and sign up. I want to take them to a separate page to complete the sign up using firebaseui. As a result, I need a way to pre-fill the email address for the EmailAuthProvider.

FYI, other users may go directly to my sign up page and will enter the email address manually.

Describe the solution you'd like

An additional option in signInOptions that allows me to specify an email address.

Describe alternatives you've considered

I currently solve this by setting the value of the "email" input in the uiShown callback. This works ok, but feels brittle as it relies on the name of the form field remaining constant over time.

It also has a visual problem if the user removes focus from the email field without editing it. In that case, the label will drop down and obscure the text (presumably because the input doesn't consider it has been dirtied?).

dmjones avatar Sep 05 '19 06:09 dmjones

@dmjones This is a reasonable use case we would like to support in future. We will look into it and keep you posted. Thanks!

wti806 avatar Sep 05 '19 18:09 wti806

@dmjones could you share your code? I'm trying the same thing, but this:

uiShown: function() {
	document.getElementById('loader').style.display = 'none';
	var mailField = document.getElementsByName('email')[0];
	console.log("mailField: ", mailField);

always give "mailField: undefined" on the console :(

j4velin avatar Oct 18 '19 16:10 j4velin

@j4velin Here's how I made it work:

const modifyLoginUI = () => {
    const emailInputField = document.getElementById('ui-sign-in-email-input');
    const userEmail = 'user@email'
    if (userEmail && userEmail !== undefined) {
      emailInputField?.setAttribute('value', userEmail);
    }
  };

The solution only works if you use email as the only sign-in option. If you provide multiple options, the approach doesn't work as the email field is not available when uiShown is called.

bhr avatar Dec 15 '20 13:12 bhr

The solution only works if you use email as the only sign-in option. If you provide multiple options, the approach doesn't work as the email field is not available when uiShown is called.

People using multiple sign-in options can use this:

      uiShown: () => {
        const container = document.getElementsByClassName(
          "login-button-container"
        )[0];
        // Options for the observer (which mutations to observe)
        const config = { childList: true, subtree: true };

        // Callback function to execute when mutations are observed
        const callback = () => {
          const emailInput = container.querySelector("#ui-sign-in-email-input");

          if (emailInput) {
            emailInput.value = '[email protected]';
            emailInput.readOnly = true;
          }
        };

        // Create an observer instance linked to the callback function
        const observer = new MutationObserver(callback);

        // Start observing the target node for configured mutations
        observer.observe(container, config);
      },

I found a uiChanged callback, but it's not documented anywhere. So, I'd be hesitant to use it.

There's also firebaseui.auth.AuthUI.prototype.startWithSignInHint, but that's not publically exposed right now (are there any plans for this?)

aheimlich avatar Dec 16 '20 00:12 aheimlich

Any update on this feature? I am in need of this now :)

arickuter avatar Aug 31 '21 07:08 arickuter

@arickuter sorry, not yet. I'll look onto this when I get time.

xil222 avatar Aug 31 '21 07:08 xil222

Awesome! Thanks @xil222

arickuter avatar Aug 31 '21 08:08 arickuter

This worked for me for web UI:

uiShown: function() {
                    // The widget is rendered.
                    // Hide the loader.
                    document.getElementById('loader').style.display = 'none';

                    const emailInput = document.getElementsByClassName(
                    "firebaseui-id-email"
                    )[0];

                    if (email) {
                        emailInput.value = email;
                        emailInput.readOnly = true;
                    }
                    
                }

tirthb avatar Jul 16 '22 04:07 tirthb

Just to add to the previous responses. If others are running into the same problem with label obscuring the text I was able to resolve the issue with the label dropping down by adding an is-dirty class to parent of the email input field.

const email = '[email protected]';
const emailInputField = document.getElementById('ui-sign-in-email-input');
emailInputField?.setAttribute('value', email);
emailInputField?.parentElement?.classList.add('is-dirty');

mdavo6 avatar Jul 18 '24 01:07 mdavo6