Created
December 17, 2018 16:59
-
-
Save torresalmonte/203df1d544474c2cf2efff7cd8fe0f4a to your computer and use it in GitHub Desktop.
firebase admin sdk send verification email
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const functions = require('firebase-functions'); | |
const admin = require('firebase-admin'); | |
admin.initializeApp({ | |
credential: admin.credential.applicationDefault() | |
}); | |
// taken from here: https://stackoverflow.com/a/41886023/4139896 | |
exports.testSendVerificationEmail = functions.https.onRequest(async (req, res) => { | |
const firebase = require('firebase'); | |
var config = { | |
/* PUT YOUR PROJECT'S WEB APP CONFIG HERE */ | |
}; | |
const app = firebase.initializeApp(config); | |
var userData = { | |
email: "[email protected]", | |
emailVerified: false, | |
}; | |
try { | |
const user = await admin.auth().createUser(userData); | |
const token = await admin.auth().createCustomToken(user.uid); | |
const result = await firebase.auth().signInWithCustomToken(token); | |
await result.user.sendEmailVerification(); | |
await firebase.auth().signOut(); | |
res.send("OK") | |
} catch (err) { | |
console.log("ERROR:", err); | |
res.send("ERROR"); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Please give this a try. I can't test it right now but I believe I have incorporated all that was required. Oh and I copied the snippets from my code that is in Typescript not Javascript. So, u might have to make some corrections here and there.
Hope it helps!