问题描述
我使用 react Native,mongo,node,我构建了完整的功能,当他“忘记密码”时向用户发送电子邮件,它在 postMan 上工作得很好,现在的问题是我不知道如何实现点击电子邮件 URL 打开“重置密码”页面中的应用程序。 我对 deepLinking 有所了解,但不明白如何使用它从点击的电子邮件中打开应用程序。
exports.sendEmail = emailData => {
const transporter = nodeMailer.createTransport({
host: "smtp.gmail.com",port: 587,secure: false,requireTLS: true,auth: {
user: "roeigr7@gmail.com",pass: "iaoqymixqarajkbv",},});
return transporter.sendMail(emailData);
};
并将数据发送到:
const emailData = {
from: "noreply@Lior.com",to: email,subject: "Password Reset Instructions",text: `Please use the following link to reset your password: ${process.env.CLIENT_URL}/resetpassword/${token}`,html: `<p>Please use the following link to reset your password:</p> <p>${process.env.CLIENT_URL}/resetpassword/${token}</p>`,
---------重置密码功能:
exports.resetPassword = (req,res) => {
const { resetPassword,newPassword } = req.body;
User.findOne({ resetPassword },(err,user) => {
// if err or no user
if (err || !user)
return res.status("401").json({
error: "Invalid Link!",});
const updatedFields = {
password: newPassword,resetPassword: "",};
user = _.extend(user,updatedFields);
user.updated = Date.Now();
user.save((err,result) => {
if (err) {
return res.status(400).json({
error: err,});
}
res.json({
message: `סיסמא שונתה בהצלחה`,});
});
});
};`
---------重置密码组件:
const resetPassword = async resetInfo => {
try {
const response = await indexApi.put("resetPassword",{
resetInfo,});
console.log("forgot password response: ",response);
} catch (err) {
console.log(err.response.data.error);
}
};
const resetPassModal = () => {
return (
<View style={{ marginVertical: 30 }}>
<Text onPress={resetPassword} style={styles.titletext}>
reset
</Text>
解决方法
这是我在 React Native 文档中读到的内容
就像使用 mailto 方案一样,可以使用自定义 url 方案链接到其他应用程序。例如,当您从 Slack 收到 Magic Link 电子邮件时,Launch Slack 按钮是一个带有 href 的锚标记,类似于:slack://secret/magic-login/other-secret。与 Slack 一样,您可以告诉操作系统您要处理自定义方案。当 Slack 应用程序打开时,它会收到用于打开它的 URL。这通常被称为深层链接。详细了解如何获取应用中的深层链接。
所以我猜当你撰写电子邮件时,你会有一个像 APP_NAME://ROUTE/TO/PASSWORD/RESET 这样的链接