You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This eliminates loading states and improves performance by avoiding the initial flags API call.
291
291
292
-
## Updating user/company/other context
292
+
## Context management
293
+
294
+
### Updating user/company/other context
293
295
294
296
Attributes given for the user/company/other context in the ReflagClient constructor can be updated for use in flag targeting evaluation with the `updateUser()`, `updateCompany()` and `updateOtherContext()` methods.
295
297
They return a promise which resolves once the flags have been re-evaluated follow the update of the attributes.
> [!NOTE] > `user`/`company` attributes are also stored remotely on the Reflag servers and will automatically be used to evaluate flag targeting if the page is refreshed.
308
310
311
+
### setContext()
312
+
313
+
The `setContext()` method allows you to replace the entire context (user, company, and other attributes) at once. This method is useful when you need to completely change the context, such as when a user logs in or switches between different accounts.
314
+
315
+
```ts
316
+
awaitreflagClient.setContext({
317
+
user: {
318
+
id: "new-user-123",
319
+
name: "Jane Doe",
320
+
email: "jane@example.com",
321
+
role: "admin",
322
+
},
323
+
company: {
324
+
id: "company-456",
325
+
name: "New Company Inc",
326
+
plan: "enterprise",
327
+
},
328
+
other: {
329
+
feature: "beta",
330
+
locale: "en-US",
331
+
},
332
+
});
333
+
```
334
+
335
+
The method will:
336
+
337
+
- Replace the entire context with the new values
338
+
- Re-evaluate all flags based on the new context
339
+
- Update the user and company information on Reflag servers
340
+
- Return a promise that resolves once the flags have been re-evaluated
341
+
342
+
### getContext()
343
+
344
+
The `getContext()` method returns the current context being used for flag evaluation. This is useful for debugging or when you need to inspect the current user, company, and other attributes.
0 commit comments