mirror of
https://github.com/FranP-code/Baileys.git
synced 2025-10-13 00:32:22 +00:00
feat: logout if myAppStateKeyId not present
This commit is contained in:
@@ -22,6 +22,7 @@ export const makeChatsSocket = (config: SocketConfig) => {
|
|||||||
sendNode,
|
sendNode,
|
||||||
query,
|
query,
|
||||||
onUnexpectedError,
|
onUnexpectedError,
|
||||||
|
logout
|
||||||
} = sock
|
} = sock
|
||||||
|
|
||||||
let privacySettings: { [_: string]: string } | undefined
|
let privacySettings: { [_: string]: string } | undefined
|
||||||
@@ -35,7 +36,14 @@ export const makeChatsSocket = (config: SocketConfig) => {
|
|||||||
const appStateSyncTimeout = debouncedTimeout(
|
const appStateSyncTimeout = debouncedTimeout(
|
||||||
APP_STATE_SYNC_TIMEOUT_MS,
|
APP_STATE_SYNC_TIMEOUT_MS,
|
||||||
async() => {
|
async() => {
|
||||||
|
if(!authState.creds.myAppStateKeyId) {
|
||||||
|
logger.warn('myAppStateKeyId not synced, bad link')
|
||||||
|
await logout('Incomplete app state key sync')
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
if(ws.readyState === ws.OPEN) {
|
if(ws.readyState === ws.OPEN) {
|
||||||
|
|
||||||
logger.info(
|
logger.info(
|
||||||
{ recvChats: Object.keys(recvChats).length },
|
{ recvChats: Object.keys(recvChats).length },
|
||||||
'doing initial app state sync'
|
'doing initial app state sync'
|
||||||
|
|||||||
@@ -396,7 +396,7 @@ export const makeSocket = ({
|
|||||||
)
|
)
|
||||||
|
|
||||||
/** logout & invalidate connection */
|
/** logout & invalidate connection */
|
||||||
const logout = async() => {
|
const logout = async(msg?: string) => {
|
||||||
const jid = authState.creds.me?.id
|
const jid = authState.creds.me?.id
|
||||||
if(jid) {
|
if(jid) {
|
||||||
await sendNode({
|
await sendNode({
|
||||||
@@ -419,7 +419,7 @@ export const makeSocket = ({
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
end(new Boom('Intentional Logout', { statusCode: DisconnectReason.loggedOut }))
|
end(new Boom(msg || 'Intentional Logout', { statusCode: DisconnectReason.loggedOut }))
|
||||||
}
|
}
|
||||||
|
|
||||||
ws.on('message', onMessageRecieved)
|
ws.on('message', onMessageRecieved)
|
||||||
|
|||||||
Reference in New Issue
Block a user