Skip to content
This repository was archived by the owner on Jan 10, 2025. It is now read-only.

Commit

Permalink
fix: 🐛 修复登录Api user 值为undefined的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
chentianyu committed Oct 9, 2023
1 parent 350af6a commit 9711eb8
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions src/route/loginCheck.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,20 @@ const { TextMsg } = require('../utils/msg')
// 登录
module.exports = function registerLoginCheck({ app, bot }) {
let message,
currentUser = null,
logOutWhenError = false,
success = false

bot
.on('scan', qrcode => {
message = 'https://wechaty.js.org/qrcode/' + encodeURIComponent(qrcode)
success = false
currentUser = null
})
.on('login', user => {
message = user + 'is already login'
success = true
currentUser = user
logOutWhenError = false
sendMsg2RecvdApi(new TextMsg({
text: JSON.stringify({ event: 'login', user }),
Expand All @@ -23,6 +26,7 @@ module.exports = function registerLoginCheck({ app, bot }) {
})
.on('logout', user => {
message = ''
currentUser = null
success = false
// 登出时给接收消息api发送特殊文本
sendMsg2RecvdApi(new TextMsg({
Expand All @@ -33,19 +37,20 @@ module.exports = function registerLoginCheck({ app, bot }) {
.on('error', error => {
// 报错时接收特殊文本
sendMsg2RecvdApi(new TextMsg({
text: JSON.stringify({ event: 'error', error }),
text: JSON.stringify({ event: 'error', error, user: currentUser }),
isSystemEvent: true
}))

// 处理异常错误后的登出上报,每次登录成功后掉线只上报一次
if (!logOutWhenError && !bot.isLoggedIn) {
logOutWhenError = true
success = false
message = ''
sendMsg2RecvdApi(new TextMsg({
text: JSON.stringify({ event: 'logout', user }),
text: JSON.stringify({ event: 'logout', user: currentUser }),
isSystemEvent: true
}))
success = false
message = ''
logOutWhenError = true
currentUser = null
}
})

Expand Down

0 comments on commit 9711eb8

Please sign in to comment.