[英]The error message from Yup's custom validation doesn't disappear
我想在注册过程中使用Yup
的自定义验证检查是否有任何重复的电子邮件:
validationSchema={yup.object().shape({
email: yup
.string()
.email()
.test({
name: 'duplicate-email-check',
params: 'value',
message: 'Duplicate email already exists',
test: async (value) => {
firebase
.auth()
.fetchSignInMethodsForEmail(value)
.then(result => {
if (result === "password") {
return false
} else {
return true
}
})
.catch(err => console.log(err))
}
})
.required(),
})}
我正在使用fetchSignInMethodsForEmail获取具有相同电子邮件的任何类型的帐户,如果存在,将抛出验证错误消息。 我在混合 ().text()模式之后建模,但问题是错误消息“重复的电子邮件已经存在”一旦出现,即使没有重复的电子邮件也不会消失。
这部分代码不返回返回布尔值进行test
的 Promise
test: async (value) => { // Notice this, adding curly braces will require you to put a return statement
firebase
.auth()
.fetchSignInMethodsForEmail(value)
.then(result => {
if (result === "password") {
return false
} else {
return true
}
})
.catch(err => console.log(err))
}
您可以将代码更改为:
test: async (value) => { // Notice this, adding curly braces will require you to put a return statement
return firebase // Notice I added the return statement
.auth()
.fetchSignInMethodsForEmail(value)
.then(result => {
if (result === "password") {
return false
} else {
return true
}
})
.catch(err => console.log(err))
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.