docs: update sdk doc with note on using multiple instances (#6311)

This commit is contained in:
Martin Emmert
2021-06-16 16:34:40 +02:00
committed by GitHub
parent dae9d97557
commit fb715cc66a

View File

@@ -68,6 +68,27 @@ The storage implementation. See [Storage](#storage) for more information.
Defaults to an instance of `MemoryStorage` when in node.js, and `LocalStorage` when in browsers.
**NOTE:**
If you plan to use multiple SDK instances at once, keep in mind that they will share the Storage across them, leading to unpredictable behaviors. This scenario might be a case while writing tests.
For example, the SDK instance that executed last the `login()` method writes the resulting `access_token` into the Storage and **overwrites** any prior fetched `access_token` from any other SDK instance. That might mix up your test scenario by granting false access rights to your previous logged-in users.
Adding prefixes to your Storage instances would solve this error:
```js
import { Directus, MemoryStorage } from "@directus/sdk";
import { randomBytes } from "crypto";
// ...
const prefix = randomBytes(8).toString("hex");
const storage = new MemoryStorage(prefix);
const url = `http://${host}:${port}`;
const directus = new Directus(url, { storage });
```
#### `options.transport`
The transport implementation. See [Transport](#transport) for more information.