I want to create and send Link "firebase dynamic link" with expire token with firebase cloud function that :
- only the user who received the mail can use it.
- Token will be expire after 24 hour.
exports.orderDynamicLink = functions.database
.ref("order/{orderId}")
.onWrite((event) => {
const options = {
method: "POST",
uri: `https://firebasedynamiclinks.googleapis.com/v1/shortLinks?key=${
functions.config().applinks.key
}`,
// I want to generate and add here the expire token
body: {
dynamicLinkInfo: {
domainUriPrefix: "https://example.page.link",
link: "https://www.example.com/",
androidInfo: {
androidPackageName: "com.example.android",
},
iosInfo: {
iosBundleId: "com.example.ios",
},
},
},
json: true,
};
request(options).then(function (parsedBody) {
console.log(parsedBody);
sendEmailLink(parsedBody.shortLink);
return parsedBody.shortLink;
});
});
function sendEmailLink(link) {
//google account credentials used to send email
var transporter = nodemailer.createTransport({
host: "smtp.gmail.com",
port: 465,
secure: true,
auth: {
user: "***********@gmail.com",
pass: "yourpassword",
},
});
const mailOptions = {
from: `***********`,
to: snap.data().email,
subject: "contact form message",
html: `<h1> tou can make a Order using this link</h1>
<p>
<b>link: </b>${link}<br>
</p>`,
};
return transporter.sendMail(mailOptions, (error, data) => {
if (error) {
console.log(error);
return;
}
console.log("Sent!");
});
}
I want to know how to achieve that : how can I create the token, how to make it expire ? how to store it ? and how to verify it when the user use the link if it valid or not ? with firebase cloud function .
Sorry for my bad English .