/
userTwo.js
49 lines (47 loc) · 1.13 KB
/
userTwo.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
exports.handler = async function(admin, snapshot, sgMail) {
const data = snapshot.data();
try {
await admin.auth().createUser({
email: data.email,
emailVerified: false,
password: Math.random()
.toString(36)
.slice(-8),
displayName: data.displayName,
photoURL: data.photoURL,
disabled: false,
uid: snapshot.id,
});
const passwordLink = await admin
.auth()
.generatePasswordResetLink(data.email);
const msg = {
personalizations: [
{
to: [
{
email: data.email,
name: data.displayName,
},
],
dynamic_template_data: {
url: passwordLink,
},
subject: 'A friend or loved one has signed you up for ReCaller!',
},
],
from: {
email: 'labsrecaller@gmail.com',
name: 'ReCaller Team',
},
reply_to: {
email: 'labsrecaller@gmail.com',
name: 'ReCaller',
},
template_id: 'd-6077c121962b439f983a559b6f3a57f8',
};
sgMail.send(msg);
} catch (e) {
throw e;
}
};