Last active
August 1, 2019 08:27
-
-
Save greghesp/01088bf957567be9257676fa52017d9b to your computer and use it in GitHub Desktop.
Using Custom Email Templates with Firebase Authentication
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
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: "[email protected]", | |
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) | |
} | |
}); |
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
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