@dynamic-labs/sdk-react-core 1.4.0 → 1.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,4 +1,11 @@
1
1
 
2
+ ### [1.4.1](https://github.com/dynamic-labs/DynamicAuth/compare/v1.4.0...v1.4.1) (2024-03-22)
3
+
4
+
5
+ ### Bug Fixes
6
+
7
+ * validate user session whenever user is connected/authenticated ([#5079](https://github.com/dynamic-labs/DynamicAuth/issues/5079)) ([d346cef](https://github.com/dynamic-labs/DynamicAuth/commit/d346cefb027305e43020b2a3b48a83bafeae4131))
8
+
2
9
  ## [1.4.0](https://github.com/dynamic-labs/DynamicAuth/compare/v1.3.1...v1.4.0) (2024-03-21)
3
10
 
4
11
 
package/package.cjs CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var version = "1.4.0";
5
+ var version = "1.4.1";
6
6
  var dependencies = {
7
7
  "@dynamic-labs/sdk-api": "0.0.387",
8
8
  "@hcaptcha/react-hcaptcha": "1.4.4",
package/package.js CHANGED
@@ -1,4 +1,4 @@
1
- var version = "1.4.0";
1
+ var version = "1.4.1";
2
2
  var dependencies = {
3
3
  "@dynamic-labs/sdk-api": "0.0.387",
4
4
  "@hcaptcha/react-hcaptcha": "1.4.4",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dynamic-labs/sdk-react-core",
3
- "version": "1.4.0",
3
+ "version": "1.4.1",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/dynamic-labs/DynamicAuth.git",
@@ -16,16 +16,16 @@
16
16
  "react-focus-lock": "2.9.2",
17
17
  "react-i18next": "^13.2.0",
18
18
  "yup": "0.32.11",
19
- "@dynamic-labs/ethereum": "1.4.0",
20
- "@dynamic-labs/iconic": "1.4.0",
21
- "@dynamic-labs/logger": "1.4.0",
22
- "@dynamic-labs/multi-wallet": "1.4.0",
23
- "@dynamic-labs/rpc-providers": "1.4.0",
24
- "@dynamic-labs/types": "1.4.0",
25
- "@dynamic-labs/utils": "1.4.0",
26
- "@dynamic-labs/viem-utils": "1.4.0",
27
- "@dynamic-labs/wallet-book": "1.4.0",
28
- "@dynamic-labs/wallet-connector-core": "1.4.0",
19
+ "@dynamic-labs/ethereum": "1.4.1",
20
+ "@dynamic-labs/iconic": "1.4.1",
21
+ "@dynamic-labs/logger": "1.4.1",
22
+ "@dynamic-labs/multi-wallet": "1.4.1",
23
+ "@dynamic-labs/rpc-providers": "1.4.1",
24
+ "@dynamic-labs/types": "1.4.1",
25
+ "@dynamic-labs/utils": "1.4.1",
26
+ "@dynamic-labs/viem-utils": "1.4.1",
27
+ "@dynamic-labs/wallet-book": "1.4.1",
28
+ "@dynamic-labs/wallet-connector-core": "1.4.1",
29
29
  "eventemitter3": "5.0.1"
30
30
  },
31
31
  "devDependencies": {
@@ -244,13 +244,6 @@ const InnerDynamicContextProvider = ({ children, theme, settings, locale: locale
244
244
  user,
245
245
  walletConnectorOptions,
246
246
  });
247
- // Ties all client callbacks to dynamic's events, such that
248
- // when our events are triggered, so are the client callbacks
249
- useTieCallbacksToEvents.useTieCallbacksToEvents({
250
- clientCallbacks: eventsCallbacks,
251
- connectedWallets,
252
- user,
253
- });
254
247
  React.useEffect(() => {
255
248
  const missingChains = getMissingChains.getMissingChains(bridgeChains, connectedWalletsInfo);
256
249
  setBridgeChainsToConnect(missingChains);
@@ -335,7 +328,7 @@ const InnerDynamicContextProvider = ({ children, theme, settings, locale: locale
335
328
  ? 2
336
329
  : 1;
337
330
  }
338
- useValidateSession.useValidateSession({
331
+ const { setHasLoggedOut } = useValidateSession.useValidateSession({
339
332
  authToken,
340
333
  handleLogOut,
341
334
  user,
@@ -343,6 +336,14 @@ const InnerDynamicContextProvider = ({ children, theme, settings, locale: locale
343
336
  walletConnectors,
344
337
  wcVersion,
345
338
  });
339
+ // Ties all client callbacks to dynamic's events, such that
340
+ // when our events are triggered, so are the client callbacks
341
+ useTieCallbacksToEvents.useTieCallbacksToEvents({
342
+ clientCallbacks: eventsCallbacks,
343
+ connectedWallets,
344
+ setHasLoggedOut,
345
+ user,
346
+ });
346
347
  const handleUnlinkWallet = useHandleUnlinkWallet.useHandleUnlinkWallet({
347
348
  environmentId,
348
349
  eventsCallbacks,
@@ -386,6 +387,7 @@ const InnerDynamicContextProvider = ({ children, theme, settings, locale: locale
386
387
  isAuthenticated,
387
388
  primaryWallet,
388
389
  secondaryWallets,
390
+ setHasLoggedOut,
389
391
  setIsVerificationInProgress,
390
392
  user,
391
393
  });
@@ -240,13 +240,6 @@ const InnerDynamicContextProvider = ({ children, theme, settings, locale, }) =>
240
240
  user,
241
241
  walletConnectorOptions,
242
242
  });
243
- // Ties all client callbacks to dynamic's events, such that
244
- // when our events are triggered, so are the client callbacks
245
- useTieCallbacksToEvents({
246
- clientCallbacks: eventsCallbacks,
247
- connectedWallets,
248
- user,
249
- });
250
243
  useEffect(() => {
251
244
  const missingChains = getMissingChains(bridgeChains, connectedWalletsInfo);
252
245
  setBridgeChainsToConnect(missingChains);
@@ -331,7 +324,7 @@ const InnerDynamicContextProvider = ({ children, theme, settings, locale, }) =>
331
324
  ? 2
332
325
  : 1;
333
326
  }
334
- useValidateSession({
327
+ const { setHasLoggedOut } = useValidateSession({
335
328
  authToken,
336
329
  handleLogOut,
337
330
  user,
@@ -339,6 +332,14 @@ const InnerDynamicContextProvider = ({ children, theme, settings, locale, }) =>
339
332
  walletConnectors,
340
333
  wcVersion,
341
334
  });
335
+ // Ties all client callbacks to dynamic's events, such that
336
+ // when our events are triggered, so are the client callbacks
337
+ useTieCallbacksToEvents({
338
+ clientCallbacks: eventsCallbacks,
339
+ connectedWallets,
340
+ setHasLoggedOut,
341
+ user,
342
+ });
342
343
  const handleUnlinkWallet = useHandleUnlinkWallet({
343
344
  environmentId,
344
345
  eventsCallbacks,
@@ -382,6 +383,7 @@ const InnerDynamicContextProvider = ({ children, theme, settings, locale, }) =>
382
383
  isAuthenticated,
383
384
  primaryWallet,
384
385
  secondaryWallets,
386
+ setHasLoggedOut,
385
387
  setIsVerificationInProgress,
386
388
  user,
387
389
  });
@@ -72,7 +72,7 @@ require('../../../../utils/hooks/useTransactionWithGasPrice/useTransactionWithGa
72
72
  require('../../../../widgets/DynamicWidget/views/ManagePasskeysWidgetView/PasskeyCard/PasskeyCard.cjs');
73
73
 
74
74
  /** Ties the customer callbacks to our events, such that our events will also trigger the callbacks */
75
- const useTieCallbacksToEvents = ({ clientCallbacks, connectedWallets, user, }) => {
75
+ const useTieCallbacksToEvents = ({ clientCallbacks, connectedWallets, user, setHasLoggedOut, }) => {
76
76
  useDynamicEvents.useInternalDynamicEvents('emailVerificationResult', (result, email) => {
77
77
  var _a, _b;
78
78
  if (result)
@@ -92,6 +92,7 @@ const useTieCallbacksToEvents = ({ clientCallbacks, connectedWallets, user, }) =
92
92
  useDynamicEvents.useInternalDynamicEvents('walletConnected', (wallet) => {
93
93
  var _a;
94
94
  (_a = clientCallbacks === null || clientCallbacks === void 0 ? void 0 : clientCallbacks.onConnect) === null || _a === void 0 ? void 0 : _a.call(clientCallbacks, { wallet, walletConnector: wallet.connector });
95
+ setHasLoggedOut(false);
95
96
  });
96
97
  useDynamicEvents.useInternalDynamicEvents('logout', () => {
97
98
  var _a;
@@ -1,8 +1,10 @@
1
+ import { Dispatch, SetStateAction } from 'react';
1
2
  import { DynamicEventsCallbacks, UserProfile, Wallet } from '../../../../shared';
2
3
  export type UseTieCallbacksToEventsParams = {
3
4
  clientCallbacks: DynamicEventsCallbacks | undefined;
4
5
  connectedWallets: Wallet[];
5
6
  user: UserProfile | undefined;
7
+ setHasLoggedOut: Dispatch<SetStateAction<boolean>>;
6
8
  };
7
9
  /** Ties the customer callbacks to our events, such that our events will also trigger the callbacks */
8
- export declare const useTieCallbacksToEvents: ({ clientCallbacks, connectedWallets, user, }: UseTieCallbacksToEventsParams) => void;
10
+ export declare const useTieCallbacksToEvents: ({ clientCallbacks, connectedWallets, user, setHasLoggedOut, }: UseTieCallbacksToEventsParams) => void;
@@ -68,7 +68,7 @@ import '../../../../utils/hooks/useTransactionWithGasPrice/useTransactionWithGas
68
68
  import '../../../../widgets/DynamicWidget/views/ManagePasskeysWidgetView/PasskeyCard/PasskeyCard.js';
69
69
 
70
70
  /** Ties the customer callbacks to our events, such that our events will also trigger the callbacks */
71
- const useTieCallbacksToEvents = ({ clientCallbacks, connectedWallets, user, }) => {
71
+ const useTieCallbacksToEvents = ({ clientCallbacks, connectedWallets, user, setHasLoggedOut, }) => {
72
72
  useInternalDynamicEvents('emailVerificationResult', (result, email) => {
73
73
  var _a, _b;
74
74
  if (result)
@@ -88,6 +88,7 @@ const useTieCallbacksToEvents = ({ clientCallbacks, connectedWallets, user, }) =
88
88
  useInternalDynamicEvents('walletConnected', (wallet) => {
89
89
  var _a;
90
90
  (_a = clientCallbacks === null || clientCallbacks === void 0 ? void 0 : clientCallbacks.onConnect) === null || _a === void 0 ? void 0 : _a.call(clientCallbacks, { wallet, walletConnector: wallet.connector });
91
+ setHasLoggedOut(false);
91
92
  });
92
93
  useInternalDynamicEvents('logout', () => {
93
94
  var _a;
@@ -1,3 +1,4 @@
1
+ import { Dispatch, SetStateAction } from 'react';
1
2
  import { JwtVerifiedCredential } from '@dynamic-labs/sdk-api';
2
3
  import { OnAuthSuccess, OnEmbeddedWalletCreated, OnLinkSuccess, OnUserProfileUpdate, UserProfile, Wallet } from '../../../shared/types';
3
4
  import { IDynamicContext } from '../types';
@@ -21,6 +22,7 @@ export type UseCustomerCallbacksArgs = {
21
22
  primaryWallet: Wallet | null;
22
23
  secondaryWallets: Wallet[];
23
24
  user: UserProfile | undefined;
25
+ setHasLoggedOut: Dispatch<SetStateAction<boolean>>;
24
26
  setIsVerificationInProgress: IDynamicContext['setIsVerificationInProgress'];
25
27
  };
26
28
  export type SetCallbackType = (callback: Callback, params?: CallbackParams) => void;
@@ -21,7 +21,7 @@ require('@dynamic-labs/multi-wallet');
21
21
  var getAuthToken = require('../../../utils/functions/getAuthToken/getAuthToken.cjs');
22
22
  require('viem/chains');
23
23
 
24
- const useCustomerCallbacks = ({ callbacks: { onAuthSuccess, onLinkSuccess, onUserProfileUpdate, onEmbeddedWalletCreated, }, handleLogOut, primaryWallet, secondaryWallets, user, isAuthenticated, setIsVerificationInProgress, }) => {
24
+ const useCustomerCallbacks = ({ callbacks: { onAuthSuccess, onLinkSuccess, onUserProfileUpdate, onEmbeddedWalletCreated, }, handleLogOut, primaryWallet, secondaryWallets, user, isAuthenticated, setIsVerificationInProgress, setHasLoggedOut, }) => {
25
25
  const [callbackQueue, setCallbackQueue] = React.useState([]);
26
26
  /** Gets the wallet from its id */
27
27
  const getWallet = React.useCallback((id) => {
@@ -44,6 +44,7 @@ const useCustomerCallbacks = ({ callbacks: { onAuthSuccess, onLinkSuccess, onUse
44
44
  user,
45
45
  walletConnector: primaryWallet === null || primaryWallet === void 0 ? void 0 : primaryWallet.connector,
46
46
  });
47
+ setHasLoggedOut(false);
47
48
  }
48
49
  catch (e) {
49
50
  logger.logger.error('Error calling onAuthSuccess: ', e);
@@ -92,6 +93,7 @@ const useCustomerCallbacks = ({ callbacks: { onAuthSuccess, onLinkSuccess, onUse
92
93
  onLinkSuccess,
93
94
  onUserProfileUpdate,
94
95
  primaryWallet,
96
+ setHasLoggedOut,
95
97
  setIsVerificationInProgress,
96
98
  ]);
97
99
  React.useEffect(() => {
@@ -1,4 +1,4 @@
1
1
  import { SetCallbackType, UseCustomerCallbacksArgs } from './types';
2
- export declare const useCustomerCallbacks: ({ callbacks: { onAuthSuccess, onLinkSuccess, onUserProfileUpdate, onEmbeddedWalletCreated, }, handleLogOut, primaryWallet, secondaryWallets, user, isAuthenticated, setIsVerificationInProgress, }: UseCustomerCallbacksArgs) => {
2
+ export declare const useCustomerCallbacks: ({ callbacks: { onAuthSuccess, onLinkSuccess, onUserProfileUpdate, onEmbeddedWalletCreated, }, handleLogOut, primaryWallet, secondaryWallets, user, isAuthenticated, setIsVerificationInProgress, setHasLoggedOut, }: UseCustomerCallbacksArgs) => {
3
3
  setCallback: SetCallbackType;
4
4
  };
@@ -17,7 +17,7 @@ import '@dynamic-labs/multi-wallet';
17
17
  import { getAuthToken } from '../../../utils/functions/getAuthToken/getAuthToken.js';
18
18
  import 'viem/chains';
19
19
 
20
- const useCustomerCallbacks = ({ callbacks: { onAuthSuccess, onLinkSuccess, onUserProfileUpdate, onEmbeddedWalletCreated, }, handleLogOut, primaryWallet, secondaryWallets, user, isAuthenticated, setIsVerificationInProgress, }) => {
20
+ const useCustomerCallbacks = ({ callbacks: { onAuthSuccess, onLinkSuccess, onUserProfileUpdate, onEmbeddedWalletCreated, }, handleLogOut, primaryWallet, secondaryWallets, user, isAuthenticated, setIsVerificationInProgress, setHasLoggedOut, }) => {
21
21
  const [callbackQueue, setCallbackQueue] = useState([]);
22
22
  /** Gets the wallet from its id */
23
23
  const getWallet = useCallback((id) => {
@@ -40,6 +40,7 @@ const useCustomerCallbacks = ({ callbacks: { onAuthSuccess, onLinkSuccess, onUse
40
40
  user,
41
41
  walletConnector: primaryWallet === null || primaryWallet === void 0 ? void 0 : primaryWallet.connector,
42
42
  });
43
+ setHasLoggedOut(false);
43
44
  }
44
45
  catch (e) {
45
46
  logger.error('Error calling onAuthSuccess: ', e);
@@ -88,6 +89,7 @@ const useCustomerCallbacks = ({ callbacks: { onAuthSuccess, onLinkSuccess, onUse
88
89
  onLinkSuccess,
89
90
  onUserProfileUpdate,
90
91
  primaryWallet,
92
+ setHasLoggedOut,
91
93
  setIsVerificationInProgress,
92
94
  ]);
93
95
  useEffect(() => {
@@ -20,9 +20,6 @@ require('../../../shared/consts/index.cjs');
20
20
 
21
21
  const useValidateSession = ({ handleLogOut, user, authToken, walletConnectV1Bridge, walletConnectors, wcVersion, }) => {
22
22
  const [hasLoggedOut, setHasLoggedOut] = React.useState(false);
23
- if (hasLoggedOut) {
24
- return;
25
- }
26
23
  const logout = (reason, params) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
27
24
  setHasLoggedOut(true);
28
25
  logger.logger.debug(`Logging out - Reason: ${reason}`, Object.assign({}, params));
@@ -77,9 +74,15 @@ const useValidateSession = ({ handleLogOut, user, authToken, walletConnectV1Brid
77
74
  oldVersion: hasWCV1Data ? 1 : 2,
78
75
  });
79
76
  });
80
- handleUserDataOutOfSync();
81
- handleConnectorBridgeOutOfSync();
82
- handleConnectorVersionOutOfSync();
77
+ const validate = () => _tslib.__awaiter(void 0, void 0, void 0, function* () {
78
+ yield handleUserDataOutOfSync();
79
+ yield handleConnectorBridgeOutOfSync();
80
+ yield handleConnectorVersionOutOfSync();
81
+ });
82
+ if (!hasLoggedOut) {
83
+ validate();
84
+ }
85
+ return { setHasLoggedOut };
83
86
  };
84
87
 
85
88
  exports.useValidateSession = useValidateSession;
@@ -1,3 +1,4 @@
1
+ /// <reference types="react" />
1
2
  import { UserProfile } from '../../../shared';
2
3
  import { WalletConnector } from '../../../..';
3
4
  type Props = {
@@ -8,5 +9,7 @@ type Props = {
8
9
  walletConnectors: WalletConnector[] | undefined;
9
10
  wcVersion: number | undefined;
10
11
  };
11
- export declare const useValidateSession: ({ handleLogOut, user, authToken, walletConnectV1Bridge, walletConnectors, wcVersion, }: Props) => void;
12
+ export declare const useValidateSession: ({ handleLogOut, user, authToken, walletConnectV1Bridge, walletConnectors, wcVersion, }: Props) => {
13
+ setHasLoggedOut: import("react").Dispatch<import("react").SetStateAction<boolean>>;
14
+ };
12
15
  export {};
@@ -16,9 +16,6 @@ import '../../../shared/consts/index.js';
16
16
 
17
17
  const useValidateSession = ({ handleLogOut, user, authToken, walletConnectV1Bridge, walletConnectors, wcVersion, }) => {
18
18
  const [hasLoggedOut, setHasLoggedOut] = useState(false);
19
- if (hasLoggedOut) {
20
- return;
21
- }
22
19
  const logout = (reason, params) => __awaiter(void 0, void 0, void 0, function* () {
23
20
  setHasLoggedOut(true);
24
21
  logger.debug(`Logging out - Reason: ${reason}`, Object.assign({}, params));
@@ -73,9 +70,15 @@ const useValidateSession = ({ handleLogOut, user, authToken, walletConnectV1Brid
73
70
  oldVersion: hasWCV1Data ? 1 : 2,
74
71
  });
75
72
  });
76
- handleUserDataOutOfSync();
77
- handleConnectorBridgeOutOfSync();
78
- handleConnectorVersionOutOfSync();
73
+ const validate = () => __awaiter(void 0, void 0, void 0, function* () {
74
+ yield handleUserDataOutOfSync();
75
+ yield handleConnectorBridgeOutOfSync();
76
+ yield handleConnectorVersionOutOfSync();
77
+ });
78
+ if (!hasLoggedOut) {
79
+ validate();
80
+ }
81
+ return { setHasLoggedOut };
79
82
  };
80
83
 
81
84
  export { useValidateSession };