This is indeed a unique query condition of the user account, obviously not good, the wechat cloud development interface is even if can not find will return a length of 0 array,
Why does this code only report an error when the account is the same as the database, but not when the account is different?
submit() {
this.$refs.uLogin.validate().then(res => {
uni.$u.toast('正在登录')
this.isConfirm = false;
setTimeout(() => {
this.isConfirm = true
const db = wx.cloud.database()
let vm = this
db.collection('userAccounts').where({
user:vm.login.userInfo.user,
}).get({
success: function(res) {
if((res.data[0].password==vm.login.userInfo.password)&&(res.data[0].user==vm.login.userInfo.user)){
uni.$u.toast('欢迎回家!');
}else{
uni.$u.toast('账号或密码错误!');
}
}
})
// 这里此提示会被this.start()方法中的提示覆盖
// 通知验证码组件内部开始倒计时
}, 2000);
// this.isConfirm=false;
}).catch(errors => {
this.isConfirm = false;
setTimeout(() => {
this.isConfirm = true
// 这里此提示会被this.start()方法中的提示覆盖
uni.$u.toast('账号或密码错误');
// 通知验证码组件内部开始倒计时
}, 2000);
})
},
0 Answer
This is indeed a unique query condition of the user account, obviously not good, the wechat cloud development interface is even if can not find will return a length of 0 array,
Debugging based on Monster groups and GPTS:
Errors in this code may be related to the results of database queries, especially if no errors are reported between accounts.
code is:
db.collection('userAccounts').where({
user: vm.login.userInfo.user
}).get({
...
})
This means that the query succeeds and results are returned only if the user account entered matches the user account in the database.
Therefore, if two different accounts have the same user account, this code may cause an error. Because whichever account queries will return the first result that matches that user's account, regardless of which account it actually belongs to. This can cause the code to produce inconsistent results across different accounts, as they may use the wrong password to authenticate the user.
To solve this problem, you can use more unique query criteria, such as user account and user ID. This ensures that the query results belong only to that user and avoids confusion with results from other accounts.
这家伙很懒,什么都没留下...