希望该站点的向导可以提供帮助。有很多类似的问题,但是Firebase方法的名称和详细信息经常更改,所以我想问一下。就我而言,我将网站托管在Firebase托管URL上,并且尝试使用电子邮件链接实现登录方法。我正在文档中复制代码:https://firebase.google.com/docs/auth/web/email-link-auth
当我尝试对此进行测试时,控制台上会显示一条错误消息:
我的代码:
import firebase from "firebase"
function SignInWithEmailLink() {
var actionCodeSettings = {
// URL you want to redirect back to. The domain (www.example.com) for this
// URL must be whitelisted in the Firebase Console.
url: 'https://myurl.web.app/',
// This must be true.
handleCodeInApp: true,
iOS: {
bundleId: 'com.example.ios'
},
android: {
packageName: 'com.example.android',
installApp: true,
minimumVersion: '12'
},
dynamicLinkDomain: 'https://myurl.web.app/'
};
function sendEmail() {
var email = document.getElementById("userEmail").value
firebase.auth().sendSignInLinkToEmail(email, actionCodeSettings)
.then(function () {
// The link was successfully sent. Inform the user.
// Save the email locally so you don't need to ask the user for it again
// if they open the link on the same device.
window.localStorage.setItem('emailForSignIn', email);
window.alert("Sending email link!")
})
.catch(function (error) {
// Some error occurred, you can inspect the code: error.code
window.alert("An error occurred...")
});
return (
<div>
<form>
<input type="text" id="userEmail" />
<button type="button" onClick={() => sendEmail()}>Send Email Link</button>
</form>
</div>
)
是的,我正在index.html上运行Firebase初始化代码段。
我认为这是400错误,表明找不到该页面。我认为这表示找不到Google验证页面,尽管我认为这可能意味着找不到自己的URL,所以我尝试更改重定向URL。我已经做了一些工作,只是保存电子邮件输入。我还刚刚验证了我的Google管理员,以确保这不是问题所在。
此外,由于catch(error)
实际上是被触发的,所以我知道firebase.auth()
正在被读取,即使不正确。
也许大家都会看到它真的很简单吗?任何意见,将不胜感激。如果您愿意,我将提供更多代码,但我认为这很重要。
答案 0 :(得分:0)
在控制台记录了一些错误之后,问题变得很明显。不支持我为dynamicLinkDomain
输入的内容。注释掉后,错误消失了。当然,我最终将不得不设置dynamicLinkDomain
,但是稍后我将越过那座桥。