Is there a way to send the verification email with the Firebase Admin SDK from my Node.js server?
Asked Answered
D

3

20

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 ?

Datha answered 14/6, 2017 at 14:31 Comment(6)
Similar post (unanswered for now): groups.google.com/forum/#!topic/firebase-talk/cWdF8gkOH3wAlumina
@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.Datha
Whoops, good point. Given that we just launched phone auth, I tend to over-interpret things as that. :-)Alumina
@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 :-)Datha
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.Alumina
@FrankvanPuffelen Done ^^Datha
A
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).

Alumina answered 15/6, 2017 at 3:22 Comment(2)
Hi, was this added in the end ?Datha
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.Jun
V
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])
Vinaigrette answered 1/2, 2019 at 23:24 Comment(1)
Email Action Link DocumentationJohnston
L
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

Lancet answered 1/8, 2020 at 14:14 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.