firebase / firebase-js-sdk

Firebase Javascript SDK
https://firebase.google.com/docs/web/setup
Other
4.84k stars 889 forks source link

sendSignInLinkToEmail not sending email #2945

Closed hreay closed 4 years ago

hreay commented 4 years ago

[REQUIRED] Describe your environment

Firebase Auth, latest version.

[REQUIRED] Describe the problem

sendSignInLinkToEmail method is successfully resolving but not sending an email on the first attempt when invoked by an already authenticated user. It does appear to send the email when the sendSignInLinkToEmail method is called a second time.

I'm wondering if perhaps the fact that the sendSignInLinkToEmail is being called by an already authenticated user is causing the issue?

Some background information: I'm using the sendSignInLinkToEmail to send a sign up link to users from an 'admin' account. The link directs the new user to the signup page which is only accessible with the link. ie. only users who are sent an email using sendSignInLinkToEmail can sign up to the app. The user can then create a password and sign in normally using signInWithEmailAndPassword. The issue is occurring when the admin user first attempts to send a sign in link to a new user. The promise resolves successfully but no email is sent to the new user. If the admin user tries a second time to add the new user the promise resolves successfully and the new user receives an email as expected.

Any help would be much appreciated!

Relevant Code:


firebase.auth().sendSignInLinkToEmail(email, actionCodeSettings)
    .then(function() {
     // this promise is resolving even though there is no email sent.
      console.log('successfully sent email to new user:', email);
    })
    .catch(function(error) {
      console.log(error)
    });
google-oss-bot commented 4 years ago

I couldn't figure out how to label this issue, so I've labeled it for a human to triage. Hang tight.

bojeil-google commented 4 years ago

Please open an issue with Firebase Support. The GitHub repo is for SDK related issues. This seems specific to your project and you will need to provide detailed sensitive information about your project, email used, etc.

On a separate note, you can't send an email link for sign-in and then call signInWithEmailAndPassword. It doesn't appear that you are using this feature correctly. If you want to create an invite link for sign up with email/password, sendSignInLinkToEmail is not designed for that.

hreay commented 4 years ago

Thanks, I've now filed a request with Firebase Support.

Apologies if I wasn't clear in my description. I'm not sending the link then using signInWithEmailAndPassword immediately. I'm using the link for the initial sign in/sign up, then once the user is authenticated using the sign in link they can create a password using firebase.auth().currentUser.updatePassword(newPassword). From then on, when the user wants to login they just use the signInWithEmailAndPassword. I guess using sendSignInLinkToEmail like this for a sign up link is not the intended use, but it seems like a neat way on managing who can sign up for the app using only the client side Firebase Auth API.