发送电子邮件验证 link 在 firebase auth expo 中不起作用
Send email verification link not working in firebase auth expo
我正在尝试创建一个只能使用现有电子邮件的注册系统。我正在尝试在他们按下按钮后向电子邮件发送电子邮件验证 link,如果通过验证,则会创建用户。这是我的功能:
userSignUp = (emailID,password,confirmPassword) => {
if(password !== confirmPassword) {
return alert("Password does not match. \n Check your password.")
}
else if(this.state.firstName !== '' &&
this.state.lastName !== '' &&
this.state.emailID !== '' &&
this.state.password !== ''){
alert('A mail has been sent to your email account. Verify it and you will be able to login.');
return firebase.auth().currentUser.sendEmailVerification()
.then(() => {
if(authUser.user.emailVerified){ //This will return true or false
firebase.auth().createUserWithEmailAndPassword(emailID, password)
.then(()=>{
//console.log(this.state)
db.collection("Users").add({
'firstName': this.state.firstName,
'lastName': this.state.lastName,
'contact': this.state.contact,
'emailID': this.state.emailID,
'password': this.state.password,
'points': 0,
'description': ''
})
return alert('Account has been created. You can now login.');
})
.catch((error) => {
// Handle Errors here.
var errorCode = error.code;
var errorMessage = error.message;
return alert(errorMessage);
});
} else {
return alert('Verification failed. Failed to create account.')
}
});
}
else if(this.state.firstName === ''){
return alert("Please enter your first name.");
}
else if(this.state.lastName === ''){
return alert("Please enter your last name.");
}
else if(this.state.emailID === ''){
return alert("Please enter your email address.");
}
else if(this.state.password === ''){
return alert("Please enter your password.");
}
}
顺便说一句,我也遇到了这个错误
TypeError: null 不是对象(正在计算 'firebase.default.auth().currentUser.sendEmailVerification')
有没有其他方法可以验证电子邮件是否存在。我正在 javascript 使用 expo 客户端。谁能帮帮我吗?谢谢
用户必须登录才能请求验证电子邮件。看来您正在尝试在登录用户之前验证用户的电子邮件,甚至首先创建他们的帐户,这目前是不可能的。所以流程应该是:
// 1. Create user account / log user in
firebase.auth().createUserWithEmailAndPassword(emailID, password).then(async ({user}) => {
// 2. Send verification email
await user.sendEmailVerification()
console.log("Verification email sent!")
})
您可以在应用程序中使用 emailVerified
属性 来提醒用户是否尚未验证电子邮件并使用安全规则限制他们的访问。
也结账:
Firebase Authentication: Verify email before sign up
Firebase email verification at SignUp
我正在尝试创建一个只能使用现有电子邮件的注册系统。我正在尝试在他们按下按钮后向电子邮件发送电子邮件验证 link,如果通过验证,则会创建用户。这是我的功能:
userSignUp = (emailID,password,confirmPassword) => {
if(password !== confirmPassword) {
return alert("Password does not match. \n Check your password.")
}
else if(this.state.firstName !== '' &&
this.state.lastName !== '' &&
this.state.emailID !== '' &&
this.state.password !== ''){
alert('A mail has been sent to your email account. Verify it and you will be able to login.');
return firebase.auth().currentUser.sendEmailVerification()
.then(() => {
if(authUser.user.emailVerified){ //This will return true or false
firebase.auth().createUserWithEmailAndPassword(emailID, password)
.then(()=>{
//console.log(this.state)
db.collection("Users").add({
'firstName': this.state.firstName,
'lastName': this.state.lastName,
'contact': this.state.contact,
'emailID': this.state.emailID,
'password': this.state.password,
'points': 0,
'description': ''
})
return alert('Account has been created. You can now login.');
})
.catch((error) => {
// Handle Errors here.
var errorCode = error.code;
var errorMessage = error.message;
return alert(errorMessage);
});
} else {
return alert('Verification failed. Failed to create account.')
}
});
}
else if(this.state.firstName === ''){
return alert("Please enter your first name.");
}
else if(this.state.lastName === ''){
return alert("Please enter your last name.");
}
else if(this.state.emailID === ''){
return alert("Please enter your email address.");
}
else if(this.state.password === ''){
return alert("Please enter your password.");
}
}
顺便说一句,我也遇到了这个错误
TypeError: null 不是对象(正在计算 'firebase.default.auth().currentUser.sendEmailVerification')
有没有其他方法可以验证电子邮件是否存在。我正在 javascript 使用 expo 客户端。谁能帮帮我吗?谢谢
用户必须登录才能请求验证电子邮件。看来您正在尝试在登录用户之前验证用户的电子邮件,甚至首先创建他们的帐户,这目前是不可能的。所以流程应该是:
// 1. Create user account / log user in
firebase.auth().createUserWithEmailAndPassword(emailID, password).then(async ({user}) => {
// 2. Send verification email
await user.sendEmailVerification()
console.log("Verification email sent!")
})
您可以在应用程序中使用 emailVerified
属性 来提醒用户是否尚未验证电子邮件并使用安全规则限制他们的访问。
也结账:
Firebase Authentication: Verify email before sign up
Firebase email verification at SignUp