按照在 JavaScript 中使用电子邮件链接通过 Firebase 进行身份验证的文档,我在 Windows 中本地运行节点。我可以使用电子邮件和密码登录,但电子邮件链接方法失败。我有这个配置:
const actionCodeSettings = {
url: 'http://localhost:5173/',
// This must be true.
handleCodeInApp: true,
iOS: {
bundleId: 'com.example.ios'
},
android: {
packageName: 'com.example.android',
installApp: true,
minimumVersion: '12'
},
dynamicLinkDomain: 'localhost'
};
和
sendSignInLinkToEmail(auth, email, actionCodeSettings)
.then(() => {
window.localStorage.setItem('emailForSignIn', email);
})
.catch((error) => {
const errorCode = error.code;
console.error(error.code);
const errorMessage = error.message;
setText(error.message);
});
localhost 已在授权域中列出 但仍然收到错误:invalid-dynamic-link-domain
我尝试将actionCodeSettings中的url和dynamicLinkDomain任意更改为不同的域。不确定是什么导致了这里的问题。
编辑: 我尝试过以下方法:
const actionCodeSettings = {
url: 'http://localhost:5173/',
// This must be true.
handleCodeInApp: true,
};
它将发送电子邮件,尽管链接 URL 是 .firebaseapp.com 域。我也在 YouTube 上看到过 this 示例,尽管我看不出我的示例有何不同。
找到了!电子邮件中使用的 URL 是从控制台设置的。
身份验证 -> 模板 -> 编辑模板 -> 自定义操作 URL。