@openfort/react-native 0.1.14 → 0.1.16
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/dist/components/AuthBoundary.js +0 -2
- package/dist/constants/config.js +1 -1
- package/dist/constants/index.js +1 -0
- package/dist/core/client.js +5 -5
- package/dist/core/index.js +3 -3
- package/dist/core/provider.js +13 -10
- package/dist/core/storage.js +5 -5
- package/dist/hooks/auth/index.js +3 -3
- package/dist/hooks/auth/useCreateWalletPostAuth.js +8 -4
- package/dist/hooks/auth/useEmailAuth.js +10 -8
- package/dist/hooks/auth/useGuestAuth.js +5 -3
- package/dist/hooks/auth/useOAuth.js +17 -11
- package/dist/hooks/auth/useSignOut.js +7 -7
- package/dist/hooks/auth/useWalletAuth.js +19 -11
- package/dist/hooks/core/useUser.js +2 -2
- package/dist/hooks/index.js +3 -2
- package/dist/hooks/wallet/useWallets.js +38 -32
- package/dist/index.js +8 -9
- package/dist/lib/logger.js +3 -11
- package/dist/native/index.js +4 -4
- package/dist/native/oauth.js +7 -12
- package/dist/native/storage.js +10 -2
- package/dist/native/webview.js +7 -5
- package/dist/types/baseFlowState.js +1 -1
- package/dist/types/components/AuthBoundary.d.ts +1 -2
- package/dist/types/components/index.d.ts +1 -1
- package/dist/types/constants/config.d.ts +1 -1
- package/dist/types/core/client.d.ts +1 -1
- package/dist/types/core/context.d.ts +2 -2
- package/dist/types/core/index.d.ts +5 -5
- package/dist/types/core/provider.d.ts +1 -1
- package/dist/types/core/storage.d.ts +1 -1
- package/dist/types/hooks/auth/index.d.ts +6 -2
- package/dist/types/hooks/auth/useCreateWalletPostAuth.d.ts +1 -15
- package/dist/types/hooks/auth/useEmailAuth.d.ts +2 -2
- package/dist/types/hooks/auth/useGuestAuth.d.ts +2 -2
- package/dist/types/hooks/auth/useOAuth.d.ts +2 -2
- package/dist/types/hooks/auth/useSignOut.d.ts +2 -2
- package/dist/types/hooks/auth/useWalletAuth.d.ts +2 -2
- package/dist/types/hooks/core/useOpenfort.d.ts +1 -1
- package/dist/types/hooks/index.d.ts +1 -1
- package/dist/types/hooks/wallet/useWallets.d.ts +4 -4
- package/dist/types/index.d.ts +4 -6
- package/dist/types/index.js +1 -1
- package/dist/types/lib/hookConsistency.d.ts +2 -2
- package/dist/types/lib/logger.d.ts +0 -2
- package/dist/types/native/index.d.ts +4 -4
- package/dist/types/native/oauth.d.ts +1 -1
- package/dist/types/native/webview.d.ts +1 -1
- package/dist/types/oauth.js +1 -1
- package/dist/types/types/baseFlowState.d.ts +2 -2
- package/dist/types/types/config.d.ts +0 -12
- package/dist/types/types/hookOption.d.ts +1 -1
- package/dist/types/types/index.d.ts +5 -5
- package/dist/types/types/predicates.d.ts +1 -1
- package/dist/types/types/wallet.d.ts +7 -7
- package/package.json +74 -19
- package/dist/hooks/auth/useAuthCallback.js +0 -1
- package/dist/types/hooks/auth/useAuthCallback.d.ts +0 -0
- package/dist/types/state.js +0 -1
- package/dist/types/types/state.d.ts +0 -0
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
1
|
import { useOpenfort } from '../hooks/core/useOpenfort';
|
|
3
2
|
/**
|
|
4
3
|
* Authentication boundary component that renders content based on authentication state.
|
|
@@ -79,4 +78,3 @@ export const AuthBoundary = ({ loading, unauthenticated, error: errorComponent,
|
|
|
79
78
|
// User is authenticated and SDK is ready
|
|
80
79
|
return React.createElement(React.Fragment, null, children);
|
|
81
80
|
};
|
|
82
|
-
export default AuthBoundary;
|
package/dist/constants/config.js
CHANGED
package/dist/constants/index.js
CHANGED
package/dist/core/client.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { Openfort as OpenfortClient } from '@openfort/openfort-js';
|
|
2
|
-
import { digest } from 'expo-crypto';
|
|
3
2
|
import { applicationId } from 'expo-application';
|
|
4
|
-
import {
|
|
3
|
+
import { digest } from 'expo-crypto';
|
|
5
4
|
import { logger } from '../lib/logger';
|
|
5
|
+
import { createNormalizedStorage, SecureStorageAdapter } from './storage';
|
|
6
6
|
/**
|
|
7
7
|
* Creates an {@link OpenfortClient} configured for Expo and React Native environments.
|
|
8
8
|
*
|
|
@@ -41,7 +41,7 @@ export function createOpenfortClient({ baseConfiguration, overrides, shieldConfi
|
|
|
41
41
|
return new OpenfortClient({
|
|
42
42
|
baseConfiguration: {
|
|
43
43
|
nativeAppIdentifier: nativeAppId,
|
|
44
|
-
...baseConfiguration
|
|
44
|
+
...baseConfiguration,
|
|
45
45
|
},
|
|
46
46
|
overrides: {
|
|
47
47
|
...overrides,
|
|
@@ -49,9 +49,9 @@ export function createOpenfortClient({ baseConfiguration, overrides, shieldConfi
|
|
|
49
49
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
50
50
|
digest: digest,
|
|
51
51
|
},
|
|
52
|
-
storage: createNormalizedStorage(SecureStorageAdapter)
|
|
52
|
+
storage: createNormalizedStorage(SecureStorageAdapter),
|
|
53
53
|
},
|
|
54
|
-
shieldConfiguration
|
|
54
|
+
shieldConfiguration,
|
|
55
55
|
});
|
|
56
56
|
}
|
|
57
57
|
/**
|
package/dist/core/index.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
// Client creation and configuration
|
|
2
|
-
export { createOpenfortClient, getDefaultClient, setDefaultClient } from './client';
|
|
3
2
|
// Re-export important types and enums from openfort-js
|
|
4
3
|
export { RecoveryMethod } from '@openfort/openfort-js';
|
|
4
|
+
export { createOpenfortClient, getDefaultClient, setDefaultClient } from './client';
|
|
5
5
|
// React context and hooks
|
|
6
|
-
export { OpenfortContext, useOpenfortContext, useOpenfortContextSafe
|
|
6
|
+
export { isOpenfortContextValue, OpenfortContext, useOpenfortContext, useOpenfortContextSafe } from './context';
|
|
7
7
|
// Main provider component
|
|
8
8
|
export { OpenfortProvider } from './provider';
|
|
9
9
|
// Storage adapters
|
|
10
|
-
export {
|
|
10
|
+
export { createNormalizedStorage, SecureStorageAdapter } from './storage';
|
package/dist/core/provider.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
import { OpenfortContext } from './context';
|
|
4
|
-
import { createOpenfortClient, setDefaultClient } from './client';
|
|
5
|
-
import { EmbeddedWalletWebView, WebViewUtils } from '../native';
|
|
6
|
-
import { logger, getEmbeddedStateName } from '../lib/logger';
|
|
1
|
+
import { EmbeddedState, ShieldConfiguration, } from '@openfort/openfort-js';
|
|
2
|
+
import React, { useCallback, useEffect, useMemo, useState } from 'react';
|
|
7
3
|
import { validateEnvironment } from '../lib/environmentValidation';
|
|
4
|
+
import { getEmbeddedStateName, logger } from '../lib/logger';
|
|
5
|
+
import { EmbeddedWalletWebView, WebViewUtils } from '../native';
|
|
6
|
+
import { createOpenfortClient, setDefaultClient } from './client';
|
|
7
|
+
import { OpenfortContext } from './context';
|
|
8
8
|
/**
|
|
9
9
|
* Starts polling the embedded wallet state and invokes the callback when transitions occur.
|
|
10
10
|
*
|
|
@@ -92,10 +92,12 @@ export const OpenfortProvider = ({ children, publishableKey, customAuth, support
|
|
|
92
92
|
baseConfiguration: {
|
|
93
93
|
publishableKey: publishableKey,
|
|
94
94
|
},
|
|
95
|
-
shieldConfiguration: walletConfig
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
95
|
+
shieldConfiguration: walletConfig
|
|
96
|
+
? new ShieldConfiguration({
|
|
97
|
+
shieldPublishableKey: walletConfig.shieldPublishableKey,
|
|
98
|
+
shieldDebug: walletConfig.debug,
|
|
99
|
+
})
|
|
100
|
+
: undefined,
|
|
99
101
|
overrides,
|
|
100
102
|
thirdPartyAuth,
|
|
101
103
|
});
|
|
@@ -216,6 +218,7 @@ export const OpenfortProvider = ({ children, publishableKey, customAuth, support
|
|
|
216
218
|
// Custom auth state management
|
|
217
219
|
useEffect(() => {
|
|
218
220
|
if (customAuth?.enabled && isUserInitialized && isClientReady) {
|
|
221
|
+
;
|
|
219
222
|
(async () => {
|
|
220
223
|
try {
|
|
221
224
|
const { getCustomAccessToken, isLoading } = customAuth;
|
package/dist/core/storage.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
2
|
import * as SecureStore from 'expo-secure-store';
|
|
3
|
-
import { NativeStorageUtils } from '../native';
|
|
4
3
|
import { logger } from '../lib/logger';
|
|
4
|
+
import { NativeStorageUtils } from '../native';
|
|
5
5
|
// Define the StorageKeys enum values that match the Openfort SDK
|
|
6
6
|
var StorageKeys;
|
|
7
7
|
(function (StorageKeys) {
|
|
@@ -105,7 +105,7 @@ export function createNormalizedStorage(customStorage) {
|
|
|
105
105
|
logger.info(`Saving to storage key: ${key}, value: ${value}`);
|
|
106
106
|
const storageKey = keyToStorageKeys(key);
|
|
107
107
|
// Fire and forget - don't await as the SDK expects synchronous behavior
|
|
108
|
-
baseStorage.save(storageKey, value).catch(error => {
|
|
108
|
+
baseStorage.save(storageKey, value).catch((error) => {
|
|
109
109
|
logger.error('Failed to save to storage', error);
|
|
110
110
|
});
|
|
111
111
|
},
|
|
@@ -113,7 +113,7 @@ export function createNormalizedStorage(customStorage) {
|
|
|
113
113
|
logger.info(`Removing from storage key: ${key}`);
|
|
114
114
|
const storageKey = keyToStorageKeys(key);
|
|
115
115
|
// Fire and forget - don't await as the SDK expects synchronous behavior
|
|
116
|
-
baseStorage.remove(storageKey).catch(error => {
|
|
116
|
+
baseStorage.remove(storageKey).catch((error) => {
|
|
117
117
|
logger.error('Failed to remove from storage', error);
|
|
118
118
|
});
|
|
119
119
|
},
|
|
@@ -134,7 +134,7 @@ export function createNormalizedStorage(customStorage) {
|
|
|
134
134
|
function keyToStorageKeys(key) {
|
|
135
135
|
if (typeof key === 'string') {
|
|
136
136
|
// Check if the string matches one of our enum values
|
|
137
|
-
const storageKey = Object.values(StorageKeys).find(value => value === key);
|
|
137
|
+
const storageKey = Object.values(StorageKeys).find((value) => value === key);
|
|
138
138
|
if (storageKey) {
|
|
139
139
|
return storageKey;
|
|
140
140
|
}
|
|
@@ -142,7 +142,7 @@ function keyToStorageKeys(key) {
|
|
|
142
142
|
// If it's an enum-like object, try to get its value
|
|
143
143
|
if (typeof key === 'object' && key !== null && 'toString' in key) {
|
|
144
144
|
const keyString = key.toString();
|
|
145
|
-
const storageKey = Object.values(StorageKeys).find(value => value === keyString);
|
|
145
|
+
const storageKey = Object.values(StorageKeys).find((value) => value === keyString);
|
|
146
146
|
if (storageKey) {
|
|
147
147
|
return storageKey;
|
|
148
148
|
}
|
package/dist/hooks/auth/index.js
CHANGED
|
@@ -5,10 +5,10 @@
|
|
|
5
5
|
*/
|
|
6
6
|
// Email authentication
|
|
7
7
|
export { useEmailAuth } from './useEmailAuth';
|
|
8
|
+
// Guest accounts
|
|
9
|
+
export { useGuestAuth } from './useGuestAuth';
|
|
8
10
|
// OAuth authentication
|
|
9
11
|
export { useOAuth } from './useOAuth';
|
|
12
|
+
export { useSignOut } from './useSignOut';
|
|
10
13
|
// Wallet-based authentication (SIWE)
|
|
11
14
|
export { useWalletAuth } from './useWalletAuth';
|
|
12
|
-
// Guest accounts
|
|
13
|
-
export { useGuestAuth } from './useGuestAuth';
|
|
14
|
-
export { useSignOut } from './useSignOut';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { useCallback } from
|
|
1
|
+
import { useCallback } from 'react';
|
|
2
2
|
/**
|
|
3
3
|
* Hook for creating wallets after user authentication.
|
|
4
4
|
*
|
|
@@ -8,10 +8,12 @@ import { useCallback } from "react";
|
|
|
8
8
|
*
|
|
9
9
|
* @returns Object containing wallet creation utilities (placeholder for now).
|
|
10
10
|
*/
|
|
11
|
-
|
|
11
|
+
const _useCreateWalletPostAuth = () => {
|
|
12
12
|
// This would connect to the wallet and set it as active
|
|
13
13
|
// eslint-disable-next-line no-empty-pattern
|
|
14
|
-
const tryUseWallet = useCallback(
|
|
14
|
+
const tryUseWallet = useCallback(
|
|
15
|
+
// async ({/* logoutOnError: signOutOnError = true, automaticRecovery = true */}: CreateWalletPostAuthOptions) => {
|
|
16
|
+
async (_props) => {
|
|
15
17
|
// if (!walletConfig || walletConfig.recoveryMethod !== RecoveryMethod.AUTOMATIC || !automaticRecovery) {
|
|
16
18
|
// return {};
|
|
17
19
|
// }
|
|
@@ -23,7 +25,9 @@ export const useCreateWalletPostAuth = () => {
|
|
|
23
25
|
// await signOut();
|
|
24
26
|
// }
|
|
25
27
|
return { wallet: undefined };
|
|
26
|
-
}, [
|
|
28
|
+
}, [
|
|
29
|
+
/* walletConfig, setActiveWallet, signOut */
|
|
30
|
+
]);
|
|
27
31
|
return {
|
|
28
32
|
tryUseWallet,
|
|
29
33
|
};
|
|
@@ -8,7 +8,7 @@ const mapStatus = (status) => {
|
|
|
8
8
|
isError: status.status === 'error',
|
|
9
9
|
isSuccess: status.status === 'done',
|
|
10
10
|
requiresEmailVerification: status.status === 'awaiting-code-input',
|
|
11
|
-
error:
|
|
11
|
+
error: 'error' in status ? status.error : null,
|
|
12
12
|
};
|
|
13
13
|
};
|
|
14
14
|
/**
|
|
@@ -76,12 +76,12 @@ export const useEmailAuth = (hookOptions = {}) => {
|
|
|
76
76
|
const error = new OpenfortError('Failed to login with email and password', OpenfortErrorType.AUTHENTICATION_ERROR, { error: e });
|
|
77
77
|
setPasswordState({
|
|
78
78
|
status: 'error',
|
|
79
|
-
error
|
|
79
|
+
error,
|
|
80
80
|
});
|
|
81
81
|
return onError({
|
|
82
82
|
hookOptions,
|
|
83
83
|
options,
|
|
84
|
-
error
|
|
84
|
+
error,
|
|
85
85
|
});
|
|
86
86
|
}
|
|
87
87
|
}, [client, setPasswordState, _internal, hookOptions]);
|
|
@@ -123,12 +123,12 @@ export const useEmailAuth = (hookOptions = {}) => {
|
|
|
123
123
|
const error = new OpenfortError('Failed to signup with email and password', OpenfortErrorType.AUTHENTICATION_ERROR, { error: e });
|
|
124
124
|
setPasswordState({
|
|
125
125
|
status: 'error',
|
|
126
|
-
error
|
|
126
|
+
error,
|
|
127
127
|
});
|
|
128
128
|
return onError({
|
|
129
129
|
hookOptions,
|
|
130
130
|
options,
|
|
131
|
-
error
|
|
131
|
+
error,
|
|
132
132
|
});
|
|
133
133
|
}
|
|
134
134
|
}, [client, setPasswordState, _internal, hookOptions]);
|
|
@@ -171,15 +171,17 @@ export const useEmailAuth = (hookOptions = {}) => {
|
|
|
171
171
|
}
|
|
172
172
|
}
|
|
173
173
|
catch (e) {
|
|
174
|
-
const error = new OpenfortError('Failed to link email and password', OpenfortErrorType.AUTHENTICATION_ERROR, {
|
|
174
|
+
const error = new OpenfortError('Failed to link email and password', OpenfortErrorType.AUTHENTICATION_ERROR, {
|
|
175
|
+
error: e,
|
|
176
|
+
});
|
|
175
177
|
setPasswordState({
|
|
176
178
|
status: 'error',
|
|
177
|
-
error
|
|
179
|
+
error,
|
|
178
180
|
});
|
|
179
181
|
return onError({
|
|
180
182
|
hookOptions,
|
|
181
183
|
options,
|
|
182
|
-
error
|
|
184
|
+
error,
|
|
183
185
|
});
|
|
184
186
|
}
|
|
185
187
|
}, [client, setPasswordState, _internal, hookOptions]);
|
|
@@ -28,7 +28,7 @@ export const useGuestAuth = (hookOptions = {}) => {
|
|
|
28
28
|
const { client, _internal } = useOpenfortContext();
|
|
29
29
|
const { refreshUserState: updateUser } = _internal;
|
|
30
30
|
const [status, setStatus] = useState({
|
|
31
|
-
status:
|
|
31
|
+
status: 'idle',
|
|
32
32
|
});
|
|
33
33
|
// const { tryUseWallet } = useCreateWalletPostAuth();
|
|
34
34
|
const signUpGuest = useCallback(async (options = {}) => {
|
|
@@ -51,10 +51,12 @@ export const useGuestAuth = (hookOptions = {}) => {
|
|
|
51
51
|
options,
|
|
52
52
|
data: { user },
|
|
53
53
|
});
|
|
54
|
-
return { user
|
|
54
|
+
return { user /* wallet */ };
|
|
55
55
|
}
|
|
56
56
|
catch (error) {
|
|
57
|
-
const openfortError = new OpenfortError(
|
|
57
|
+
const openfortError = new OpenfortError('Failed to signup guest', OpenfortErrorType.AUTHENTICATION_ERROR, {
|
|
58
|
+
error,
|
|
59
|
+
});
|
|
58
60
|
setStatus({
|
|
59
61
|
status: 'error',
|
|
60
62
|
error: openfortError,
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { OAuthProvider } from '@openfort/openfort-js';
|
|
2
2
|
import { useCallback } from 'react';
|
|
3
3
|
import { useOpenfortContext } from '../../core/context';
|
|
4
|
+
import { onError, onSuccess } from '../../lib/hookConsistency';
|
|
4
5
|
import { authenticateWithApple, createOAuthRedirectUri, isAppleSignInAvailable, OAuthUtils, openOAuthSession, parseOAuthUrl, } from '../../native';
|
|
5
|
-
import { mapOAuthStatus } from
|
|
6
|
+
import { mapOAuthStatus } from '../../types/oauth';
|
|
6
7
|
import { OpenfortError, OpenfortErrorType } from '../../types/openfortError';
|
|
7
|
-
import { onError, onSuccess } from '../../lib/hookConsistency';
|
|
8
8
|
/**
|
|
9
9
|
* Hook for OAuth-based authentication with supported providers.
|
|
10
10
|
*
|
|
@@ -44,7 +44,7 @@ export const useOAuth = (hookOptions = {}) => {
|
|
|
44
44
|
options: {
|
|
45
45
|
skipBrowserRedirect: true,
|
|
46
46
|
redirectTo: redirectUri,
|
|
47
|
-
}
|
|
47
|
+
},
|
|
48
48
|
});
|
|
49
49
|
// Handle OAuth flow using native utilities
|
|
50
50
|
setOAuthState({ status: 'awaiting-redirect' });
|
|
@@ -73,7 +73,9 @@ export const useOAuth = (hookOptions = {}) => {
|
|
|
73
73
|
});
|
|
74
74
|
}
|
|
75
75
|
catch (e) {
|
|
76
|
-
const error = new OpenfortError('Apple authentication failed', OpenfortErrorType.AUTHENTICATION_ERROR, {
|
|
76
|
+
const error = new OpenfortError('Apple authentication failed', OpenfortErrorType.AUTHENTICATION_ERROR, {
|
|
77
|
+
error: e,
|
|
78
|
+
});
|
|
77
79
|
setOAuthState({
|
|
78
80
|
status: 'error',
|
|
79
81
|
error,
|
|
@@ -140,10 +142,12 @@ export const useOAuth = (hookOptions = {}) => {
|
|
|
140
142
|
}
|
|
141
143
|
}
|
|
142
144
|
catch (e) {
|
|
143
|
-
const error = new OpenfortError('OAuth initialization failed', OpenfortErrorType.AUTHENTICATION_ERROR, {
|
|
145
|
+
const error = new OpenfortError('OAuth initialization failed', OpenfortErrorType.AUTHENTICATION_ERROR, {
|
|
146
|
+
error: e,
|
|
147
|
+
});
|
|
144
148
|
setOAuthState({
|
|
145
149
|
status: 'error',
|
|
146
|
-
error
|
|
150
|
+
error,
|
|
147
151
|
});
|
|
148
152
|
return onError({
|
|
149
153
|
options,
|
|
@@ -168,7 +172,7 @@ export const useOAuth = (hookOptions = {}) => {
|
|
|
168
172
|
options: {
|
|
169
173
|
skipBrowserRedirect: true,
|
|
170
174
|
redirectTo: redirectUri,
|
|
171
|
-
}
|
|
175
|
+
},
|
|
172
176
|
});
|
|
173
177
|
// Handle OAuth linking flow using native utilities
|
|
174
178
|
setOAuthState({ status: 'awaiting-redirect' });
|
|
@@ -184,7 +188,7 @@ export const useOAuth = (hookOptions = {}) => {
|
|
|
184
188
|
// Complete OAuth linking flow with Apple credentials
|
|
185
189
|
const linkResult = await client.auth.loginWithIdToken({
|
|
186
190
|
provider: OAuthProvider.APPLE,
|
|
187
|
-
token: appleResult.identityToken
|
|
191
|
+
token: appleResult.identityToken,
|
|
188
192
|
});
|
|
189
193
|
setOAuthState({ status: 'done' });
|
|
190
194
|
const user = linkResult.player;
|
|
@@ -197,7 +201,9 @@ export const useOAuth = (hookOptions = {}) => {
|
|
|
197
201
|
});
|
|
198
202
|
}
|
|
199
203
|
catch (e) {
|
|
200
|
-
const error = new OpenfortError('Apple linking failed', OpenfortErrorType.AUTHENTICATION_ERROR, {
|
|
204
|
+
const error = new OpenfortError('Apple linking failed', OpenfortErrorType.AUTHENTICATION_ERROR, {
|
|
205
|
+
error: e,
|
|
206
|
+
});
|
|
201
207
|
setOAuthState({
|
|
202
208
|
status: 'error',
|
|
203
209
|
error,
|
|
@@ -267,12 +273,12 @@ export const useOAuth = (hookOptions = {}) => {
|
|
|
267
273
|
const error = new OpenfortError('OAuth linking failed', OpenfortErrorType.AUTHENTICATION_ERROR, { error: e });
|
|
268
274
|
setOAuthState({
|
|
269
275
|
status: 'error',
|
|
270
|
-
error
|
|
276
|
+
error,
|
|
271
277
|
});
|
|
272
278
|
return onError({
|
|
273
279
|
options,
|
|
274
280
|
hookOptions,
|
|
275
|
-
error
|
|
281
|
+
error,
|
|
276
282
|
});
|
|
277
283
|
}
|
|
278
284
|
}, [client, setOAuthState, _internal]);
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { useCallback, useState } from
|
|
2
|
-
import { useOpenfortContext } from
|
|
3
|
-
import { onError, onSuccess } from
|
|
4
|
-
import { mapStatus } from
|
|
5
|
-
import { OpenfortError, OpenfortErrorType } from
|
|
6
|
-
import { useOpenfortClient } from
|
|
1
|
+
import { useCallback, useState } from 'react';
|
|
2
|
+
import { useOpenfortContext } from '../../core';
|
|
3
|
+
import { onError, onSuccess } from '../../lib/hookConsistency';
|
|
4
|
+
import { mapStatus } from '../../types/baseFlowState';
|
|
5
|
+
import { OpenfortError, OpenfortErrorType } from '../../types/openfortError';
|
|
6
|
+
import { useOpenfortClient } from '../core';
|
|
7
7
|
/**
|
|
8
8
|
* Hook for user sign out functionality
|
|
9
9
|
*
|
|
@@ -40,7 +40,7 @@ export function useSignOut(hookOptions = {}) {
|
|
|
40
40
|
const client = useOpenfortClient();
|
|
41
41
|
const { _internal, user } = useOpenfortContext();
|
|
42
42
|
const [status, setStatus] = useState({
|
|
43
|
-
status:
|
|
43
|
+
status: 'idle',
|
|
44
44
|
});
|
|
45
45
|
const signOut = useCallback(async (options = {}) => {
|
|
46
46
|
if (!user)
|
|
@@ -4,10 +4,12 @@ import { onError, onSuccess } from '../../lib/hookConsistency';
|
|
|
4
4
|
import { OpenfortError, OpenfortErrorType } from '../../types/openfortError';
|
|
5
5
|
const mapStatus = (status) => {
|
|
6
6
|
return {
|
|
7
|
-
isLoading: status.status === 'generating-message' ||
|
|
7
|
+
isLoading: status.status === 'generating-message' ||
|
|
8
|
+
status.status === 'awaiting-signature' ||
|
|
9
|
+
status.status === 'submitting-signature',
|
|
8
10
|
isError: status.status === 'error',
|
|
9
11
|
isSuccess: status.status === 'done',
|
|
10
|
-
error:
|
|
12
|
+
error: 'error' in status ? status.error : null,
|
|
11
13
|
isAwaitingSignature: status.status === 'awaiting-signature',
|
|
12
14
|
isGeneratingMessage: status.status === 'generating-message',
|
|
13
15
|
isSubmittingSignature: status.status === 'submitting-signature',
|
|
@@ -63,12 +65,14 @@ export function useWalletAuth(hookOptions) {
|
|
|
63
65
|
const errorObj = error instanceof Error ? error : new Error('Failed to generate SIWE message');
|
|
64
66
|
setSiweState({
|
|
65
67
|
status: 'error',
|
|
66
|
-
error: errorObj
|
|
68
|
+
error: errorObj,
|
|
67
69
|
});
|
|
68
70
|
return onError({
|
|
69
71
|
hookOptions,
|
|
70
72
|
options: args,
|
|
71
|
-
error: new OpenfortError('Failed to generate SIWE message', OpenfortErrorType.AUTHENTICATION_ERROR, {
|
|
73
|
+
error: new OpenfortError('Failed to generate SIWE message', OpenfortErrorType.AUTHENTICATION_ERROR, {
|
|
74
|
+
error: errorObj,
|
|
75
|
+
}),
|
|
72
76
|
});
|
|
73
77
|
}
|
|
74
78
|
}, [client, setSiweState]);
|
|
@@ -101,15 +105,17 @@ export function useWalletAuth(hookOptions) {
|
|
|
101
105
|
});
|
|
102
106
|
}
|
|
103
107
|
catch (e) {
|
|
104
|
-
const error = new OpenfortError('Failed to link in with Ethereum', OpenfortErrorType.AUTHENTICATION_ERROR, {
|
|
108
|
+
const error = new OpenfortError('Failed to link in with Ethereum', OpenfortErrorType.AUTHENTICATION_ERROR, {
|
|
109
|
+
error: e,
|
|
110
|
+
});
|
|
105
111
|
setSiweState({
|
|
106
112
|
status: 'error',
|
|
107
|
-
error
|
|
113
|
+
error,
|
|
108
114
|
});
|
|
109
115
|
return onError({
|
|
110
116
|
hookOptions,
|
|
111
117
|
options: opts,
|
|
112
|
-
error
|
|
118
|
+
error,
|
|
113
119
|
});
|
|
114
120
|
}
|
|
115
121
|
}, [client, siweState, setSiweState, _internal]);
|
|
@@ -124,7 +130,7 @@ export function useWalletAuth(hookOptions) {
|
|
|
124
130
|
signature: opts.signature,
|
|
125
131
|
message: message,
|
|
126
132
|
walletClientType: 'unknown',
|
|
127
|
-
connectorType: 'unknown'
|
|
133
|
+
connectorType: 'unknown',
|
|
128
134
|
});
|
|
129
135
|
setSiweState({ status: 'done' });
|
|
130
136
|
const user = result.player;
|
|
@@ -137,15 +143,17 @@ export function useWalletAuth(hookOptions) {
|
|
|
137
143
|
});
|
|
138
144
|
}
|
|
139
145
|
catch (e) {
|
|
140
|
-
const error = new OpenfortError('Failed to sign in with Ethereum', OpenfortErrorType.AUTHENTICATION_ERROR, {
|
|
146
|
+
const error = new OpenfortError('Failed to sign in with Ethereum', OpenfortErrorType.AUTHENTICATION_ERROR, {
|
|
147
|
+
error: e,
|
|
148
|
+
});
|
|
141
149
|
setSiweState({
|
|
142
150
|
status: 'error',
|
|
143
|
-
error
|
|
151
|
+
error,
|
|
144
152
|
});
|
|
145
153
|
return onError({
|
|
146
154
|
hookOptions,
|
|
147
155
|
options: opts,
|
|
148
|
-
error
|
|
156
|
+
error,
|
|
149
157
|
});
|
|
150
158
|
}
|
|
151
159
|
}, [client, siweState, setSiweState, _internal]);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { EmbeddedState } from
|
|
2
|
-
import { useOpenfortContext } from
|
|
1
|
+
import { EmbeddedState } from '@openfort/openfort-js';
|
|
2
|
+
import { useOpenfortContext } from '../../core';
|
|
3
3
|
/**
|
|
4
4
|
* Hook for accessing current user state and authentication status
|
|
5
5
|
*
|
package/dist/hooks/index.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
// biome-ignore-all lint/performance/noReExportAll: This is an index file that re-exports everything
|
|
1
2
|
/**
|
|
2
3
|
* Openfort React Native SDK hooks.
|
|
3
4
|
*
|
|
@@ -8,9 +9,9 @@
|
|
|
8
9
|
* - Auth: Authentication helpers (email, OAuth, SIWE, guest)
|
|
9
10
|
* - Wallet: Embedded wallet management utilities
|
|
10
11
|
*/
|
|
11
|
-
// Re-export all core hooks
|
|
12
|
-
export * from './core';
|
|
13
12
|
// Re-export all authentication hooks
|
|
14
13
|
export * from './auth';
|
|
14
|
+
// Re-export all core hooks
|
|
15
|
+
export * from './core';
|
|
15
16
|
// Re-export all wallet hooks
|
|
16
17
|
export * from './wallet';
|