Javascript user.emailVerified不会在响应sendEmailVerification链接(firebase auth)时更改为“true”
有人请帮忙,我错过了什么?我成功地使用firebase sendEmailVerification发送验证电子邮件,当我单击电子邮件上的链接时,该链接不起作用,因此我最终复制了该链接并粘贴到浏览器上,然后按enter键。这样我就可以返回到我的web应用程序,继续URL也可以正常工作。这不会将user.emaiVerified更改为trueJavascript user.emailVerified不会在响应sendEmailVerification链接(firebase auth)时更改为“true”,javascript,firebase-authentication,Javascript,Firebase Authentication,有人请帮忙,我错过了什么?我成功地使用firebase sendEmailVerification发送验证电子邮件,当我单击电子邮件上的链接时,该链接不起作用,因此我最终复制了该链接并粘贴到浏览器上,然后按enter键。这样我就可以返回到我的web应用程序,继续URL也可以正常工作。这不会将user.emaiVerified更改为true const user = firebase.auth().currentUser if(user) { user.sendEmailVerificat
const user = firebase.auth().currentUser
if(user) {
user.sendEmailVerification(actionCodeSettings)
.then( () => {
console.log("UnpSignUpForm: Verification email sent SUCCESSFULLY");
})
.catch( (error) => {
console.log('UnpSignUpForm: Verification email sending error: ', error)
});
} else {
console.log('no user')
}
firebase.auth().onAuthStateChanged( user => {
// console.log('onAuthStateChanged user', user)
if (user) {
console.log('onAuthStateChanged: user is signed IN')
console.log('onAuthStateChanged user', user)
user.reload()
console.log(`user ${user.email} reloaded`)
// User is signed in.
if(user.emailVerified) {
console.log('onAuthStateChanged:email Verified', user.emailVerified)
} else {
console.log('onAuthStateChanged:email NOT Verified', user.emailVerified)
}
} else {
console.log('onAuthStateChanged: onAuthStateChanged: user is signed OUT')
}
});
我尝试在onAuthStateChanged中使用user.reload,请参见下文,但仍然无法将user.emailVerified更改为true
const user = firebase.auth().currentUser
if(user) {
user.sendEmailVerification(actionCodeSettings)
.then( () => {
console.log("UnpSignUpForm: Verification email sent SUCCESSFULLY");
})
.catch( (error) => {
console.log('UnpSignUpForm: Verification email sending error: ', error)
});
} else {
console.log('no user')
}
firebase.auth().onAuthStateChanged( user => {
// console.log('onAuthStateChanged user', user)
if (user) {
console.log('onAuthStateChanged: user is signed IN')
console.log('onAuthStateChanged user', user)
user.reload()
console.log(`user ${user.email} reloaded`)
// User is signed in.
if(user.emailVerified) {
console.log('onAuthStateChanged:email Verified', user.emailVerified)
} else {
console.log('onAuthStateChanged:email NOT Verified', user.emailVerified)
}
} else {
console.log('onAuthStateChanged: onAuthStateChanged: user is signed OUT')
}
});
用户单击链接后,emailVerified不会自动更新。它将在用户重新加载时更新,例如user.reload
此外,令牌声明中的email_verified字段将在令牌过期后自然刷新时更新,或者如果在用户电子邮件验证后强制令牌刷新,例如user.getIdTokentrue。在用户单击链接后,emailVerified不会自动更新。它将在用户重新加载时更新,例如user.reload
此外,令牌声明中的email_verified字段将在令牌过期后自然刷新时更新,或者在用户电子邮件验证后强制令牌刷新时更新,例如user.getIdTokentrue。我希望您能找到问题所在。我刚想出来。我在用React 当您收到验证密码的电子邮件时,您会注意到该链接如下所示: 如果检查URL,您会注意到4个参数: 模式 卵码 阿皮基 朗 当您单击该链接时,您将被转发到firebase控制台中设置的url 当您访问验证电子邮件中的url时,需要找到解析查询参数的方法。有一个很好的npm包,它为你做所有的脏活。它还有易于阅读的文档,我发现在React上很容易实现 从url参数解析oobCode后,我将其用作以下方法的参数:
firebase.auth().applyActionCode(<add the oobCode here>)
.then(() => {
// handle success here
}).catch(err => {
//handle failure here
});
我希望你能找出问题所在。我刚想出来。我在用React 当您收到验证密码的电子邮件时,您会注意到该链接如下所示: 如果检查URL,您会注意到4个参数: 模式 卵码 阿皮基 朗 当您单击该链接时,您将被转发到firebase控制台中设置的url 当您访问验证电子邮件中的url时,需要找到解析查询参数的方法。有一个很好的npm包,它为你做所有的脏活。它还有易于阅读的文档,我发现在React上很容易实现 从url参数解析oobCode后,我将其用作以下方法的参数:
firebase.auth().applyActionCode(<add the oobCode here>)
.then(() => {
// handle success here
}).catch(err => {
//handle failure here
});
谢谢你的回复。我尝试了user.getIdTokentrue,但仍然不起作用。如果我能找到一个链接,详细说明firebase/auth如何在引擎盖下工作。可能是可以帮助的。user.getIdTokentrue仅更新令牌内的电子邮件\u验证声明。user.emailVerified仅在user reload.tnx上更新您的响应。我尝试了user.getIdTokentrue,但仍然不起作用。如果我能找到一个链接,详细说明firebase/auth如何在引擎盖下工作。可能是可以帮助的。user.getIdTokentrue仅更新令牌内的电子邮件\u验证声明。user.emailVerified仅在用户重新加载时更新。