18

Is there a way to send the email verification email from my server ?

This is how it's done on the client:

authData.sendEmailVerification().then(function() {

Is there a way to do it on the server ?

TheProgrammer
  • 1,409
  • 4
  • 24
  • 53
  • Similar post (unanswered for now): https://groups.google.com/forum/#!topic/firebase-talk/cWdF8gkOH3w – Frank van Puffelen Jun 14 '17 at 14:36
  • @FrankvanPuffelen Similar indeed although I think it's important to point out that my issue is with Email verification, the other gentleman's issue being with Phone authentication. – TheProgrammer Jun 14 '17 at 14:51
  • Whoops, good point. Given that we just launched phone auth, I tend to over-interpret things as that. :-) – Frank van Puffelen Jun 14 '17 at 15:09
  • 1
    @FrankvanPuffelen ^^ Regardless, Gio from Firebase Support told me there was currently no way to send the verification email from the server. Is this a feature that's on Firebase's radar or not at all ? I already ended up reworking my code to to send the email using the firebase client SDK, but I am still curious :-) – TheProgrammer Jun 14 '17 at 16:25
  • I just checked all the docs, because I fully expected to be able to send those verification messages from the Admin SDK. But indeed: it doesn't seem to be there. I'd recommend [you file a feature request](https://firebase.google.com/support/contact/bugs-features/). – Frank van Puffelen Jun 14 '17 at 16:38
  • @FrankvanPuffelen Done ^^ – TheProgrammer Jun 14 '17 at 17:17

3 Answers3

14

firebaser here

To my surprise there currently is no option to send verification email from within the Admin SDK. I'd recommend you file a feature request.

What you can do from the Admin SDK is update a user profile to mark their email as verified. This allows you to take control of the entire verification flow if you want to, finishing with a call to admin.auth().updateUser(...) (on Node.js, see the link for other supported languages).

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
  • Hi, was this added in the end ? – TheProgrammer Jan 25 '18 at 12:26
  • 1
    I cannot find evidence that it was added, and the more I thought about the problem, the more it made sense to keep this client-side, and the more my server-side admin approach seemed unnecessary. Re-sending of verification emails should really be handled by an error / button generated client-side when authentication is checked client-side. – Matthew Rideout Feb 27 '18 at 17:15
10

I just came across the same problem as you. There is a function to generate the verification link using user's email address.

I used this function on an array of email addresses, then load the result to my mail automation API to send mails out. This function is weirdly not documented:

admin.auth().generateEmailVerificationLink([EMAIL_ADDRESS])
ansidev
  • 361
  • 1
  • 3
  • 17
Linh
  • 418
  • 4
  • 9
  • 1
    [Email Action Link Documentation](https://firebase.google.com/docs/auth/admin/email-action-links) – ansidev May 16 '19 at 07:14
3

You can use :

axios.post('https://identitytoolkit.googleapis.com/v1/accounts:sendOobCode?key=[API_KEY]',
    { requestType: 'VERIFY_EMAIL', idToken: response.data.idToken }
)

https://firebase.google.com/docs/reference/rest/auth#section-send-email-verification

benomatis
  • 5,536
  • 7
  • 36
  • 59