Skip to content

Add info about Firebase Storage RemoteAuth plugin #88

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 60 additions & 1 deletion src/guide/creating-your-bot/authentication.md
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,65 @@ const client = new Client({
});
```

#### Cloud Storage for Firebase (Firebase Storage) Store

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:

<CodeGroup>
<CodeGroupItem title="NPM" active>

```bash
npm install wwebjs-firebase-storage
```

</CodeGroupItem>
<CodeGroupItem title="YARN">

```bash
yarn add wwebjs-firebase-storage
```

</CodeGroupItem>
<CodeGroupItem title="PNPM">

```bash
pnpm add wwebjs-firebase-storage
```

</CodeGroupItem>
</CodeGroup>

Once the package is installed, you have to import it and pass it to the `RemoteAuth`strategy as follows:

```js
import { Client, RemoteAuth } from 'whatsapp-web.js';
import { initializeApp, getStorage, FirebaseStorageStore } from 'wwebjs-firebase-storage';
import qrcode_terminal from 'qrcode-terminal';
const app = initializeApp({
apiKey: <firebase-api-key>,
projectId: <firebase-project-id>,
storageBucket: <firebase-storage-bucket>,
});
const client = new Client({
authStrategy: new RemoteAuth({
store: new FirebaseStorageStore({
firebaseStorage: getStorage(app),
// sessionPath: 'sessions-whatsapp-web.js', <- optional setting to save in a sub-directory
}),
backupSyncIntervalMs: 600000,
}),
... // other options
});
client.on('qr', qr => {
qrcode_terminal.generate(qr, {small: true});
});
client.on('remote_session_saved', () => console.log('Remote session saved!'));
client.on('authenticated', () => console.log('Authenticated!'));
client.on('auth_failure', () => console.log('Authentication failed!'));
client.on('ready', () => console.log('Client is ready!'));
client.initialize();
```

### Session Saved

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:
Expand All @@ -282,4 +341,4 @@ client.on('remote_session_saved', () => {
| :-------: |:--------------------------------- |
| ✅ | MacOS |
| ✅ | Windows |
| ✅ | Ubuntu 20.04 (Heroku Compatible) |
| ✅ | Ubuntu 20.04 (Heroku Compatible) |