Update README.md (#1698)

Fix README.md with reference of constant 'saveCreds' correct on 'creds.update' event.
This commit is contained in:
Paulo Corcino
2022-06-05 08:49:45 -03:00
committed by GitHub
parent b7d8401f62
commit b78ffe029a

View File

@@ -145,12 +145,12 @@ import * as fs from 'fs'
// utility function to help save the auth state in a single folder
// this function serves as a good guide to help write auth & key states for SQL/no-SQL databases, which I would recommend in any production grade system
const { state, saveCreds } = useMultiFileAuthState('auth_info_baileys')
const { state, saveCreds } = await useMultiFileAuthState('auth_info_baileys')
// will use the given state to connect
// so if valid credentials are available -- it'll connect without QR
const conn = makeWASocket({ auth: state })
// this will be called as soon as the credentials are updated
conn.ev.on ('creds.update', saveState)
conn.ev.on ('creds.update', saveCreds)
```
**Note**: When a message is received/sent, due to signal sessions needing updating, the auth keys (`authState.keys`) will update. Whenever that happens, you must save the updated keys (`authState.keys.set()` is called). Not doing so will prevent your messages from reaching the recipient & other unexpected consequences. The `useMultiFileAuthState` function automatically takes care of that, but for any other serious implementation -- you will need to be very careful with the key state management.