Skip to content

Commit e12c9a2

Browse files
committed
feat: expose token as client setting
1 parent 794f522 commit e12c9a2

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

packages/react-headless/src/components/MagicBellProvider/MagicBellProvider.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ export interface MagicBellProviderProps {
1919
userEmail?: string;
2020
userExternalId?: string;
2121
userKey?: string;
22+
token?: string;
2223
children: React.ReactElement | React.ReactElement[];
2324
stores?: StoreConfig[];
2425
serverURL?: string;
@@ -54,6 +55,7 @@ function setupStores(storesConfig: StoreConfig[]) {
5455
* @param props.userEmail Email of the user whose notifications will be displayed
5556
* @param props.userExternalId External ID of the user whose notifications will be displayed
5657
* @param props.userKey Computed HMAC of the user whose notifications will be displayed, compute this with the secret of the magicbell project
58+
* @param props.token User token that can be used to authenticate instead of using the apiKey + userEmail/userExternalID combination
5759
* @param props.stores List of stores to be created
5860
* @param props.disableRealtime Disable realtime updates
5961
*

packages/react-headless/src/stores/clientSettings.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ export type ClientSettings = {
88
userEmail?: string;
99
userExternalId?: string;
1010
userKey?: string;
11+
token?: string;
1112
clientId: string;
1213
serverURL: string;
1314
getClient(): InstanceType<typeof UserClient>;
@@ -30,13 +31,14 @@ const clientSettings = createStore<ClientSettings>((set, get) => {
3031
userEmail: undefined,
3132
userExternalId: undefined,
3233
userKey: undefined,
34+
token: undefined,
3335
clientId: Math.random().toString(36).substring(2) + Date.now(),
3436
serverURL: 'https://api.magicbell.com',
3537
appInfo: undefined,
3638

3739
getClient() {
3840
const state = get();
39-
const key = JSON.stringify([state.apiKey, state.userEmail, state.userExternalId, state.userKey]);
41+
const key = JSON.stringify([state.apiKey, state.userEmail, state.userExternalId, state.userKey, state.token]);
4042

4143
if (key !== _key) {
4244
_key = key;
@@ -45,6 +47,7 @@ const clientSettings = createStore<ClientSettings>((set, get) => {
4547
userEmail: state.userEmail,
4648
userHmac: state.userKey,
4749
apiKey: state.apiKey,
50+
token: state.token,
4851
host: state.serverURL,
4952
appInfo: state.appInfo || {
5053
name: pkg.name,

0 commit comments

Comments
 (0)