Skip to content

fix: resolve pairing code rejection due to timing and platform validation issues#2409

Open
mtAlves wants to merge 1 commit intoWhiskeySockets:masterfrom
mtAlves:fix/pairing-code
Open

fix: resolve pairing code rejection due to timing and platform validation issues#2409
mtAlves wants to merge 1 commit intoWhiskeySockets:masterfrom
mtAlves:fix/pairing-code

Conversation

@mtAlves
Copy link
Copy Markdown
Contributor

@mtAlves mtAlves commented Mar 11, 2026

requestPairingCode was sending the link_code_companion_reg IQ before the server signaled readiness via pair-device, and setting creds.me before server confirmation — causing 428, 401, and 400 responses.

Changes:

  • Extract sendPairingIQ from requestPairingCode to separate IQ dispatch from readiness gate logic
  • Add pairingReady gate: queue requestPairingCode calls that arrive before pair-device is received, flushing them when the event fires
  • Add pairingInProgress guard to reject concurrent pairing requests
  • Defer creds.me assignment to after the companion_hello query succeeds, preventing reconnects from taking the login path instead of registration
  • Reject pending pairing promises and reset state on socket close/error
  • Fix getPlatformId return value (now consistently returns string)
  • Add getPlatformDisplayName to resolve the display label for a platform type

The pairing IQ now validates companion_platform_id and companion_platform_display against server-accepted values: only browser-type platform IDs (CHROME=1..EDGE=6) are accepted; DESKTOP (7) is rejected. Custom brand names in browser[0] are preserved through DeviceProps.os (shown in WhatsApp's Linked Devices list) but are normalised to a canonical OS name in the pairing IQ itself.

…tion issues

requestPairingCode was sending the link_code_companion_reg IQ before the
server signaled readiness via pair-device, and setting creds.me before
server confirmation — causing 428, 401, and 400 responses.

Changes in src/Socket/socket.ts:
- Extract sendPairingIQ from requestPairingCode to separate IQ dispatch
  from readiness gate logic
- Add pairingReady gate: queue requestPairingCode calls that arrive before
  pair-device is received, flushing them when the event fires
- Add pairingInProgress guard to reject concurrent pairing requests
- Defer creds.me assignment to after the companion_hello query succeeds,
  preventing reconnects from taking the login path instead of registration
- Reject pending pairing promises and reset state on socket close/error

Changes in src/Utils/browser-utils.ts:
- Fix getPlatformId return value (now consistently returns string)
- Add getPlatformDisplayName to resolve the display label for a platform type

The pairing IQ now validates companion_platform_id and companion_platform_display
against server-accepted values: only browser-type platform IDs (CHROME=1..EDGE=6)
are accepted; DESKTOP (7) is rejected. Custom brand names in browser[0] are
preserved through DeviceProps.os (shown in WhatsApp's Linked Devices list) but
are normalised to a canonical OS name in the pairing IQ itself.
@whiskeysockets-bot
Copy link
Copy Markdown
Contributor

Thanks for opening this pull request and contributing to the project!

The next step is for the maintainers to review your changes. If everything looks good, it will be approved and merged into the main branch.

In the meantime, anyone in the community is encouraged to test this pull request and provide feedback.

✅ How to confirm it works

If you’ve tested this PR, please comment below with:

Tested and working ✅

This helps us speed up the review and merge process.

📦 To test this PR locally:

# NPM
npm install @whiskeysockets/baileys@mtAlves/Baileys#fix/pairing-code

# Yarn (v2+)
yarn add @whiskeysockets/baileys@mtAlves/Baileys#fix/pairing-code

# PNPM
pnpm add @whiskeysockets/baileys@mtAlves/Baileys#fix/pairing-code

If you encounter any issues or have feedback, feel free to comment as well.

@devrhapp
Copy link
Copy Markdown

Uma duvida essas alteracoes vai afetar o tipo plataforma exemplo MACO, ou DESKTOP como telatado acima na descrição. Uso o valor MACO = 21 usava desktop que era o valor 14 . segundo relatos em outras prs o valor 14 nao e aceito mas pela meta.

O IQ de emparelhamento agora valida companion_platform_id e companion_platform_display em relação aos valores aceitos pelo servidor: somente IDs de plataforma do tipo navegador (CHROME=1..EDGE=6) são aceitos; DESKTOP (7) é rejeitado. Nomes de marca personalizados em browser[0] são preservados por meio de DeviceProps.os (exibidos na lista de Dispositivos Vinculados do WhatsApp), mas são normalizados para um nome de SO canônico no próprio IQ de emparelhamento.

@vielhuber
Copy link
Copy Markdown

This is important, since connecting with pairing code does not work atm.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 1, 2026

This PR is stale because it has been open for 14 days with no activity. Remove the stale label or comment or this will be closed in 14 days

@github-actions github-actions bot added the Stale label Apr 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

Status: Backlog

Development

Successfully merging this pull request may close these issues.

5 participants