From fb715cc66a2013474968bf079bf402d464b5e55b Mon Sep 17 00:00:00 2001 From: Martin Emmert Date: Wed, 16 Jun 2021 16:34:40 +0200 Subject: [PATCH] docs: update sdk doc with note on using multiple instances (#6311) --- docs/reference/sdk.md | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/docs/reference/sdk.md b/docs/reference/sdk.md index ce17436023..ec5a79fb98 100644 --- a/docs/reference/sdk.md +++ b/docs/reference/sdk.md @@ -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.