Skip to content

Instantly share code, notes, and snippets.

@greghesp
Last active August 1, 2019 08:27
Show Gist options
  • Save greghesp/01088bf957567be9257676fa52017d9b to your computer and use it in GitHub Desktop.
Save greghesp/01088bf957567be9257676fa52017d9b to your computer and use it in GitHub Desktop.
Using Custom Email Templates with Firebase Authentication
exports.verifyEmail = functions.auth.user().onCreate(async(user) => {
try {
const token = crypto.randomBytes(48);
await admin.firestore().collection("users").doc(user.uid).set({
name: user.displayName,
});
await admin.firestore().collection("activationTokens").doc(user.uid).set({
token: token.toString('hex'),
expires: Date.now() + ( 3600 * 1000 * 24)
});
const email = new Email ({
message: {
from: "noreply@domain.com",
subject: "Activate your Account!",
to: user.email
},
send: true,
transport: {
host: "smtp.mailtrap.io",
port: 2525,
auth: {
user: "abc",
pass: "123"
}
},
views: {
options: {
extension: 'ejs'
}
}
});
return email.send({
template: 'activateAccount',
locals: {
name: user.displayName,
url: data.url
},
});
} catch (e) {
console.log(e)
}
});
function handleSubmit(form) {
try {
await firebase.auth().createUserWithEmailAndPassword(form.email, form.password);
} catch (e) {
console.log(e);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment