Skip to content

Commit 6549f5d

Browse files
Add info about Firebase Storage RemoteAuth plugin
1 parent 5161349 commit 6549f5d

File tree

1 file changed

+60
-1
lines changed

1 file changed

+60
-1
lines changed

src/guide/creating-your-bot/authentication.md

Lines changed: 60 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,65 @@ const client = new Client({
266266
});
267267
```
268268

269+
#### Cloud Storage for Firebase (Firebase Storage) Store
270+
271+
Before you can use this Auth strategy you need to install the [`wwebjs-firebase-storage`](https://github.com/vedantmgoyal9/wwebjs-firebase-storage) module in your terminal:
272+
273+
<CodeGroup>
274+
<CodeGroupItem title="NPM" active>
275+
276+
```bash
277+
npm install wwebjs-firebase-storage
278+
```
279+
280+
</CodeGroupItem>
281+
<CodeGroupItem title="YARN">
282+
283+
```bash
284+
yarn add wwebjs-firebase-storage
285+
```
286+
287+
</CodeGroupItem>
288+
<CodeGroupItem title="PNPM">
289+
290+
```bash
291+
pnpm add wwebjs-firebase-storage
292+
```
293+
294+
</CodeGroupItem>
295+
</CodeGroup>
296+
297+
Once the package is installed, you have to import it and pass it to the `RemoteAuth`strategy as follows:
298+
299+
```js
300+
import { Client, RemoteAuth } from 'whatsapp-web.js';
301+
import { initializeApp, getStorage, FirebaseStorageStore } from 'wwebjs-firebase-storage';
302+
import qrcode_terminal from 'qrcode-terminal';
303+
const app = initializeApp({
304+
apiKey: <firebase-api-key>,
305+
projectId: <firebase-project-id>,
306+
storageBucket: <firebase-storage-bucket>,
307+
});
308+
const client = new Client({
309+
authStrategy: new RemoteAuth({
310+
store: new FirebaseStorageStore({
311+
firebaseStorage: getStorage(app),
312+
// sessionPath: 'sessions-whatsapp-web.js', <- optional setting to save in a sub-directory
313+
}),
314+
backupSyncIntervalMs: 600000,
315+
}),
316+
... // other options
317+
});
318+
client.on('qr', qr => {
319+
qrcode_terminal.generate(qr, {small: true});
320+
});
321+
client.on('remote_session_saved', () => console.log('Remote session saved!'));
322+
client.on('authenticated', () => console.log('Authenticated!'));
323+
client.on('auth_failure', () => console.log('Authentication failed!'));
324+
client.on('ready', () => console.log('Client is ready!'));
325+
client.initialize();
326+
```
327+
269328
### Session Saved
270329

271330
After the initial QR scan to link the device, RemoteAuth takes about `1 minute` to successfully save the WhatsApp session into the remote database, therefore the ready event does not mean the session has been saved yet. In order to listen to this event, you can now use the following:
@@ -282,4 +341,4 @@ client.on('remote_session_saved', () => {
282341
| :-------: |:--------------------------------- |
283342
|| MacOS |
284343
|| Windows |
285-
|| Ubuntu 20.04 (Heroku Compatible) |
344+
|| Ubuntu 20.04 (Heroku Compatible) |

0 commit comments

Comments
 (0)