@openfort/react-native 0.1.23 → 0.1.24

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.
@@ -173,6 +173,12 @@ export const OpenfortProvider = ({ children, publishableKey, supportedChains, wa
173
173
  // Internal refresh function for auth hooks to use
174
174
  const refreshUserState = useCallback(async (user) => {
175
175
  try {
176
+ // If null is passed explicitly, clear the user state without API call
177
+ if (user === null) {
178
+ logger.info('Clearing user state explicitly');
179
+ handleUserChange(null);
180
+ return null;
181
+ }
176
182
  if (user === undefined) {
177
183
  logger.info('Refreshing user state, no user provided');
178
184
  }
@@ -1,4 +1,4 @@
1
- import { useCallback, useState } from 'react';
1
+ import { useCallback, useRef, useState } from 'react';
2
2
  import { useOpenfortContext } from '../../core';
3
3
  import { onError, onSuccess } from '../../lib/hookConsistency';
4
4
  import { mapStatus } from '../../types/baseFlowState';
@@ -42,37 +42,37 @@ export function useSignOut(hookOptions = {}) {
42
42
  const [status, setStatus] = useState({
43
43
  status: 'idle',
44
44
  });
45
+ // Use refs for unstable values to prevent infinite re-renders
46
+ const userRef = useRef(user);
47
+ const internalRef = useRef(_internal);
48
+ const hookOptionsRef = useRef(hookOptions);
49
+ userRef.current = user;
50
+ internalRef.current = _internal;
51
+ hookOptionsRef.current = hookOptions;
45
52
  const signOut = useCallback(async (options = {}) => {
46
- if (!user)
53
+ if (!userRef.current)
47
54
  return;
48
- setStatus({
49
- status: 'loading',
50
- });
55
+ setStatus({ status: 'loading' });
51
56
  try {
52
57
  await client.auth.logout();
53
- _internal.refreshUserState();
54
- setStatus({
55
- status: 'success',
56
- });
58
+ await internalRef.current.refreshUserState(null);
59
+ setStatus({ status: 'success' });
57
60
  return onSuccess({
58
- hookOptions,
61
+ hookOptions: hookOptionsRef.current,
59
62
  options,
60
63
  data: {},
61
64
  });
62
65
  }
63
66
  catch (e) {
64
67
  const error = new OpenfortError('Failed to sign out', OpenfortErrorType.AUTHENTICATION_ERROR, { error: e });
65
- setStatus({
66
- status: 'error',
67
- error,
68
- });
68
+ setStatus({ status: 'error', error });
69
69
  return onError({
70
- hookOptions,
70
+ hookOptions: hookOptionsRef.current,
71
71
  options,
72
72
  error,
73
73
  });
74
74
  }
75
- }, [client, user, _internal.refreshUserState, setStatus, hookOptions]);
75
+ }, [client]);
76
76
  return {
77
77
  ...mapStatus(status),
78
78
  signOut,
@@ -38,7 +38,7 @@ export interface OpenfortContextValue {
38
38
  getAccessToken: () => Promise<string | null>;
39
39
  /** @internal Refreshes user state after authentication changes. */
40
40
  _internal: {
41
- refreshUserState: (user?: import('@openfort/openfort-js').AuthPlayerResponse) => Promise<import('@openfort/openfort-js').AuthPlayerResponse | null>;
41
+ refreshUserState: (user?: import('@openfort/openfort-js').AuthPlayerResponse | null) => Promise<import('@openfort/openfort-js').AuthPlayerResponse | null>;
42
42
  };
43
43
  }
44
44
  /**
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@openfort/react-native",
3
3
  "main": "dist/index.js",
4
- "version": "0.1.23",
4
+ "version": "0.1.24",
5
5
  "license": "MIT",
6
6
  "description": "React Native SDK for Openfort platform integration",
7
7
  "types": "dist/types/index.d.ts",