@openfort/react 0.0.12 → 0.0.13
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/build/assets/browsers.d.ts +1 -1
- package/build/assets/logos.d.ts +1 -0
- package/build/components/Openfort/OpenfortProvider.d.ts +25 -12
- package/build/components/Openfort/context.d.ts +2 -0
- package/build/components/Openfort/types.d.ts +19 -15
- package/build/components/Pages/EmailLogin/styles.d.ts +1 -0
- package/build/components/Pages/Providers/styles.d.ts +2 -0
- package/build/components/PasswordStrength/password-utility.d.ts +50 -16
- package/build/components/contexts/web3/index.d.ts +18 -1
- package/build/constants/openfort.d.ts +0 -1
- package/build/defaultTransports.d.ts +27 -4
- package/build/hooks/openfort/auth/useAuthCallback.d.ts +63 -0
- package/build/hooks/openfort/auth/useConnectToWalletPostAuth.d.ts +26 -4
- package/build/hooks/openfort/auth/useEmailAuth.d.ts +71 -0
- package/build/hooks/openfort/auth/useGuestAuth.d.ts +59 -0
- package/build/hooks/openfort/auth/useOAuth.d.ts +74 -0
- package/build/hooks/openfort/auth/useSignOut.d.ts +57 -0
- package/build/hooks/openfort/useStatus.d.ts +42 -0
- package/build/hooks/openfort/useUI.d.ts +63 -0
- package/build/hooks/openfort/useUser.d.ts +44 -0
- package/build/hooks/openfort/useWallet.d.ts +50 -0
- package/build/hooks/openfort/useWallets.d.ts +56 -0
- package/build/hooks/useChainIsSupported.d.ts +24 -1
- package/build/hooks/useChains.d.ts +39 -0
- package/build/hooks/useConnect.d.ts +18 -10
- package/build/index.es.js +3362 -2541
- package/build/index.es.js.map +1 -1
- package/build/openfort/core/client.d.ts +26 -7
- package/build/styles/styled/index.d.ts +5 -7
- package/build/styles/themes/base.d.ts +12 -12
- package/build/styles/themes/minimal.d.ts +2 -17
- package/build/styles/themes/retro.d.ts +3 -1
- package/build/styles/themes/rounded.d.ts +3 -1
- package/build/styles/themes/web95.d.ts +3 -1
- package/build/utils/localstorage.d.ts +61 -2
- package/build/version.d.ts +1 -1
- package/build/wallets/walletConfigs.d.ts +2 -2
- package/package.json +1 -1
- package/build/components/Pages/EmailSignup/index.d.ts +0 -3
package/build/assets/logos.d.ts
CHANGED
|
@@ -89,6 +89,7 @@ export declare const providersLogos: {
|
|
|
89
89
|
twitter: import("react/jsx-runtime").JSX.Element;
|
|
90
90
|
facebook: import("react/jsx-runtime").JSX.Element;
|
|
91
91
|
discord: import("react/jsx-runtime").JSX.Element;
|
|
92
|
+
apple: import("react/jsx-runtime").JSX.Element;
|
|
92
93
|
};
|
|
93
94
|
declare const _default: {
|
|
94
95
|
Mock: ({ ...props }: {
|
|
@@ -13,19 +13,32 @@ type OpenfortProviderProps = {
|
|
|
13
13
|
thirdPartyAuth?: ThirdPartyAuthConfiguration;
|
|
14
14
|
} & useConnectCallbackProps;
|
|
15
15
|
/**
|
|
16
|
-
*
|
|
17
|
-
* It must be used within a WagmiProvider.
|
|
16
|
+
* Provides Openfort configuration and context to descendant components.
|
|
18
17
|
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
* @param
|
|
23
|
-
* @
|
|
24
|
-
* @
|
|
25
|
-
*
|
|
26
|
-
* @
|
|
27
|
-
*
|
|
28
|
-
*
|
|
18
|
+
* The provider must be rendered within a {@link WagmiContext} and should only be mounted once
|
|
19
|
+
* to avoid conflicting global state. See {@link OpenfortProviderProps} for the supported options.
|
|
20
|
+
*
|
|
21
|
+
* @param props - Provider configuration including callbacks, UI options and the wrapped children.
|
|
22
|
+
* @returns A React element that sets up the Openfort context.
|
|
23
|
+
* @throws If the component is rendered outside of a Wagmi provider or mounted multiple times.
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* ```tsx
|
|
27
|
+
* import { WagmiConfig, createConfig } from 'wagmi';
|
|
28
|
+
* import { OpenfortProvider } from '@openfort/openfort-react';
|
|
29
|
+
*
|
|
30
|
+
* const config = createConfig({ YOU_WAGMI_CONFIG_HERE });
|
|
31
|
+
*
|
|
32
|
+
* export function App() {
|
|
33
|
+
* return (
|
|
34
|
+
* <WagmiConfig config={config}>
|
|
35
|
+
* <OpenfortProvider publishableKey={process.env.NEXT_PUBLIC_PUBLISHABLE_KEY!}>
|
|
36
|
+
* <YourApp />
|
|
37
|
+
* </OpenfortProvider>
|
|
38
|
+
* </WagmiConfig>
|
|
39
|
+
* );
|
|
40
|
+
* }
|
|
41
|
+
* ```
|
|
29
42
|
*/
|
|
30
43
|
export declare const OpenfortProvider: ({ children, uiConfig, onConnect, onDisconnect, debugMode, publishableKey, walletConfig, overrides, thirdPartyAuth, }: OpenfortProviderProps) => React.FunctionComponentElement<React.ProviderProps<ContextValue | null>>;
|
|
31
44
|
export {};
|
|
@@ -35,6 +35,8 @@ export type ContextValue = {
|
|
|
35
35
|
walletConfig?: OpenfortWalletConfig;
|
|
36
36
|
overrides?: SDKOverrides;
|
|
37
37
|
thirdPartyAuth?: ThirdPartyAuthConfiguration;
|
|
38
|
+
emailInput: string;
|
|
39
|
+
setEmailInput: React.Dispatch<React.SetStateAction<string>>;
|
|
38
40
|
} & useConnectCallbackProps;
|
|
39
41
|
export declare const Openfortcontext: React.Context<ContextValue | null>;
|
|
40
42
|
export {};
|
|
@@ -8,7 +8,6 @@ export declare const routes: {
|
|
|
8
8
|
readonly LOADING: "loading";
|
|
9
9
|
readonly RECOVER: "recover";
|
|
10
10
|
readonly EMAIL_LOGIN: "emailLogin";
|
|
11
|
-
readonly EMAIL_SIGNUP: "emailSignup";
|
|
12
11
|
readonly FORGOT_PASSWORD: "forgotPassword";
|
|
13
12
|
readonly EMAIL_VERIFICATION: "emailVerification";
|
|
14
13
|
readonly LINK_EMAIL: "linkEmail";
|
|
@@ -26,6 +25,7 @@ export declare enum UIAuthProvider {
|
|
|
26
25
|
TWITTER = "twitter",
|
|
27
26
|
FACEBOOK = "facebook",
|
|
28
27
|
DISCORD = "discord",
|
|
28
|
+
APPLE = "apple",
|
|
29
29
|
EMAIL = "email",
|
|
30
30
|
WALLET = "wallet",
|
|
31
31
|
GUEST = "guest"
|
|
@@ -33,33 +33,29 @@ export declare enum UIAuthProvider {
|
|
|
33
33
|
export declare const socialProviders: UIAuthProvider[];
|
|
34
34
|
type PolicyConfig = string | Record<number, string>;
|
|
35
35
|
type CommonWalletConfig = {
|
|
36
|
-
/** Publishable key for the Shield API */
|
|
36
|
+
/** Publishable key for the Shield API. */
|
|
37
37
|
shieldPublishableKey: string;
|
|
38
|
-
/** Policy ID (pol_...) for the embedded signer */
|
|
38
|
+
/** Policy ID (pol_...) for the embedded signer. */
|
|
39
39
|
ethereumProviderPolicyId?: PolicyConfig;
|
|
40
40
|
accountType?: AccountTypeEnum;
|
|
41
41
|
debug?: boolean;
|
|
42
42
|
};
|
|
43
43
|
type EncryptionSession = {
|
|
44
|
-
/** Function to retrieve an encryption session using a session ID */
|
|
44
|
+
/** Function to retrieve an encryption session using a session ID. */
|
|
45
45
|
getEncryptionSession?: (accessToken: string) => Promise<string>;
|
|
46
46
|
createEncryptedSessionEndpoint?: never;
|
|
47
47
|
} | {
|
|
48
|
-
/** API endpoint for creating an encrypted session */
|
|
48
|
+
/** API endpoint for creating an encrypted session. */
|
|
49
49
|
getEncryptionSession?: never;
|
|
50
50
|
createEncryptedSessionEndpoint?: string;
|
|
51
51
|
};
|
|
52
52
|
/**
|
|
53
|
-
* Configuration for
|
|
54
|
-
* - An encryption session is required.
|
|
53
|
+
* Configuration for wallet recovery behaviour.
|
|
55
54
|
*
|
|
56
|
-
*
|
|
57
|
-
*
|
|
58
|
-
*
|
|
59
|
-
*
|
|
60
|
-
* Encryption session can be created using either:
|
|
61
|
-
* - `createEncryptedSessionEndpoint` as a string, OR
|
|
62
|
-
* - `getEncryptionSession.` as a function that returns a promise.
|
|
55
|
+
* @remarks
|
|
56
|
+
* Automatic recovery requires an encryption session, which may be supplied via
|
|
57
|
+
* the `createEncryptedSessionEndpoint` endpoint or the `getEncryptionSession` callback.
|
|
58
|
+
* Password-based and passkey-based recovery methods do not require encryption sessions.
|
|
63
59
|
*/
|
|
64
60
|
export type OpenfortWalletConfig = CommonWalletConfig & EncryptionSession;
|
|
65
61
|
export type OpenfortUIOptions = {
|
|
@@ -85,17 +81,20 @@ export type ConnectUIOptions = {
|
|
|
85
81
|
hideTooltips?: boolean;
|
|
86
82
|
hideRecentBadge?: boolean;
|
|
87
83
|
walletConnectCTA?: 'link' | 'modal' | 'both';
|
|
84
|
+
/** Avoids layout shift when the Openfort modal is open by adding padding to the body. */
|
|
88
85
|
avoidLayoutShift?: boolean;
|
|
86
|
+
/** Automatically embeds the Google font of the current theme. Does not work with custom themes. */
|
|
89
87
|
embedGoogleFonts?: boolean;
|
|
90
88
|
truncateLongENSAddress?: boolean;
|
|
91
89
|
walletConnectName?: string;
|
|
92
90
|
reducedMotion?: boolean;
|
|
93
91
|
disclaimer?: ReactNode | string;
|
|
94
|
-
/** Buffer
|
|
92
|
+
/** Buffer polyfill, needed for bundlers that do not provide Node polyfills (e.g. CRA, Vite, etc.). */
|
|
95
93
|
bufferPolyfill?: boolean;
|
|
96
94
|
customAvatar?: React.FC<CustomAvatarProps>;
|
|
97
95
|
initialChainId?: number;
|
|
98
96
|
enforceSupportedChains?: boolean;
|
|
97
|
+
/** Blur intensity applied to the background when the modal is open. */
|
|
99
98
|
overlayBlur?: number;
|
|
100
99
|
walletRecovery?: WalletRecoveryOptions;
|
|
101
100
|
} & Partial<OpenfortUIOptions>;
|
|
@@ -114,19 +113,24 @@ export type OpenfortUIOptionsExtended = {
|
|
|
114
113
|
hideNoWalletCTA?: boolean;
|
|
115
114
|
hideRecentBadge?: boolean;
|
|
116
115
|
walletConnectCTA?: 'link' | 'modal' | 'both';
|
|
116
|
+
/** Avoids layout shift when the Openfort modal is open by adding padding to the body. */
|
|
117
117
|
avoidLayoutShift?: boolean;
|
|
118
|
+
/** Automatically embeds the Google font of the current theme. Does not work with custom themes. */
|
|
118
119
|
embedGoogleFonts?: boolean;
|
|
119
120
|
truncateLongENSAddress?: boolean;
|
|
120
121
|
walletConnectName?: string;
|
|
121
122
|
reducedMotion?: boolean;
|
|
122
123
|
disclaimer?: ReactNode | string;
|
|
124
|
+
/** Buffer polyfill, needed for bundlers that do not provide Node polyfills (e.g. CRA, Vite, etc.). */
|
|
123
125
|
bufferPolyfill?: boolean;
|
|
124
126
|
customAvatar?: React.FC<CustomAvatarProps>;
|
|
125
127
|
initialChainId?: number;
|
|
126
128
|
enforceSupportedChains?: boolean;
|
|
127
129
|
ethereumOnboardingUrl?: string;
|
|
128
130
|
walletOnboardingUrl?: string;
|
|
131
|
+
/** Disable redirect to the SIWE page after a wallet is connected. */
|
|
129
132
|
disableSiweRedirect?: boolean;
|
|
133
|
+
/** Blur intensity applied to the background when the modal is open. */
|
|
130
134
|
overlayBlur?: number;
|
|
131
135
|
walletRecovery: WalletRecoveryOptionsExtended;
|
|
132
136
|
} & OpenfortUIOptions;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const FooterContainer: import("styled-components").StyledComponent<"span", any, {}, never>;
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
export declare const ProviderInputInner: import("styled-components").StyledComponent<"div", any, {}, never>;
|
|
2
|
+
export declare const EmailInnerButton: import("styled-components").StyledComponent<import("framer-motion").ForwardRefComponent<HTMLButtonElement, import("framer-motion").HTMLMotionProps<"button">>, any, {}, never>;
|
|
1
3
|
export declare const ProvidersButton: import("styled-components").StyledComponent<"div", any, {}, never>;
|
|
2
4
|
export declare const ProviderLabel: import("styled-components").StyledComponent<"span", any, {}, never>;
|
|
3
5
|
export declare const ProviderIcon: import("styled-components").StyledComponent<"div", any, {}, never>;
|
|
@@ -1,52 +1,86 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Password
|
|
3
|
-
*
|
|
4
|
-
* and password validation.
|
|
2
|
+
* Password utility helpers for strength calculation and validation.
|
|
3
|
+
*
|
|
4
|
+
* Provides functions for password strength calculation, passphrase generation, and password validation.
|
|
5
5
|
*/
|
|
6
6
|
export declare const MEDIUM_SCORE_THRESHOLD = 0.5;
|
|
7
7
|
export declare const STRONG_SCORE_THRESHOLD = 0.75;
|
|
8
8
|
export declare const VERY_STRONG_SCORE_THRESHOLD = 0.9;
|
|
9
|
-
/**
|
|
9
|
+
/**
|
|
10
|
+
* Password strength levels.
|
|
11
|
+
*/
|
|
10
12
|
export type PasswordStrengthLabel = 'Weak' | 'Medium' | 'Strong' | 'Very Strong';
|
|
11
|
-
/**
|
|
13
|
+
/**
|
|
14
|
+
* Password summary information.
|
|
15
|
+
*/
|
|
12
16
|
export interface PasswordSummary {
|
|
13
17
|
value: number;
|
|
14
18
|
label: PasswordStrengthLabel;
|
|
15
19
|
}
|
|
16
20
|
/**
|
|
17
21
|
* Gets a list of invalid characters in the provided text.
|
|
18
|
-
* Replaces spaces with 'SPACE' for visibility.
|
|
19
22
|
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
23
|
+
* Replaces spaces with `SPACE` for visibility.
|
|
24
|
+
*
|
|
25
|
+
* @param text - The text to check for invalid characters.
|
|
26
|
+
* @returns Array of unique invalid characters.
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* ```ts
|
|
30
|
+
* const invalid = getInvalidCharacters('Pa$$ word');
|
|
31
|
+
* // invalid === ['$', 'SPACE']
|
|
32
|
+
* ```
|
|
22
33
|
*/
|
|
23
34
|
export declare function getInvalidCharacters(text?: string): string[];
|
|
24
35
|
/**
|
|
25
36
|
* Converts a numeric password strength score to a human-readable label.
|
|
26
37
|
*
|
|
27
|
-
* @param score - The strength score (0-1)
|
|
28
|
-
* @returns The corresponding strength label
|
|
38
|
+
* @param score - The strength score (0-1).
|
|
39
|
+
* @returns The corresponding strength label.
|
|
40
|
+
*
|
|
41
|
+
* @example
|
|
42
|
+
* ```ts
|
|
43
|
+
* const label = getPasswordStrengthLabel(0.8);
|
|
44
|
+
* // label === 'Strong'
|
|
45
|
+
* ```
|
|
29
46
|
*/
|
|
30
47
|
export declare function getPasswordStrengthLabel(score: number): PasswordStrengthLabel;
|
|
31
48
|
/**
|
|
32
49
|
* Calculates the diversity score of a password based on character types used.
|
|
50
|
+
*
|
|
33
51
|
* Considers lowercase, uppercase, digits, and special characters.
|
|
34
52
|
*
|
|
35
|
-
* @param password - The password to
|
|
36
|
-
* @returns A score between 0 and 1 representing character diversity
|
|
53
|
+
* @param password - The password to analyse.
|
|
54
|
+
* @returns A score between 0 and 1 representing character diversity.
|
|
55
|
+
*
|
|
56
|
+
* @example
|
|
57
|
+
* ```ts
|
|
58
|
+
* const diversity = calculatePasswordDiversityScore('Password123!');
|
|
59
|
+
* ```
|
|
37
60
|
*/
|
|
38
61
|
export declare function calculatePasswordDiversityScore(password: string): number;
|
|
39
62
|
/**
|
|
40
63
|
* Calculates the overall password strength combining diversity and entropy.
|
|
41
64
|
*
|
|
42
|
-
* @param password - The password to
|
|
43
|
-
* @returns A strength score between 0 and 1
|
|
65
|
+
* @param password - The password to analyse.
|
|
66
|
+
* @returns A strength score between 0 and 1.
|
|
67
|
+
*
|
|
68
|
+
* @example
|
|
69
|
+
* ```ts
|
|
70
|
+
* const strength = getPasswordStrength('Password123!');
|
|
71
|
+
* ```
|
|
44
72
|
*/
|
|
45
73
|
export declare function getPasswordStrength(password?: string): number;
|
|
46
74
|
/**
|
|
47
75
|
* Gets a comprehensive summary of password strength.
|
|
48
76
|
*
|
|
49
|
-
* @param password - The password to
|
|
50
|
-
* @returns An object containing the strength value and label
|
|
77
|
+
* @param password - The password to analyse.
|
|
78
|
+
* @returns An object containing the strength value and label.
|
|
79
|
+
*
|
|
80
|
+
* @example
|
|
81
|
+
* ```ts
|
|
82
|
+
* const summary = getPasswordSummary('Password123!');
|
|
83
|
+
* // summary === { value: 0.74, label: 'Strong' }
|
|
84
|
+
* ```
|
|
51
85
|
*/
|
|
52
86
|
export declare function getPasswordSummary(password?: string): PasswordSummary;
|
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Provides reusable Web3 state and helpers to descendant components.
|
|
3
|
+
*
|
|
4
|
+
* @example
|
|
5
|
+
* ```tsx
|
|
6
|
+
* <Web3ContextProvider>
|
|
7
|
+
* <WalletSelector />
|
|
8
|
+
* </Web3ContextProvider>
|
|
9
|
+
* ```
|
|
3
10
|
*/
|
|
4
11
|
import { Address, Chain } from 'viem';
|
|
5
12
|
type Web3Context = {
|
|
@@ -20,5 +27,15 @@ export declare const Web3ContextProvider: ({ enabled, children, }: {
|
|
|
20
27
|
enabled?: boolean;
|
|
21
28
|
children: React.ReactNode;
|
|
22
29
|
}) => import("react/jsx-runtime").JSX.Element;
|
|
30
|
+
/**
|
|
31
|
+
* React hook to access the {@link Web3Context} values.
|
|
32
|
+
*
|
|
33
|
+
* @returns Shared Web3 utilities exposed by the provider.
|
|
34
|
+
*
|
|
35
|
+
* @example
|
|
36
|
+
* ```ts
|
|
37
|
+
* const { account } = useWeb3();
|
|
38
|
+
* ```
|
|
39
|
+
*/
|
|
23
40
|
export declare const useWeb3: () => Web3Context;
|
|
24
41
|
export {};
|
|
@@ -1,15 +1,38 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
* Developers using this causes loss of granular control over a dapps transports,
|
|
5
|
-
* but for simple use cases, it's nice to have and saves a lot of boilerplate.
|
|
2
|
+
* Helpers for constructing default Wagmi transports for supported chains.
|
|
6
3
|
*
|
|
4
|
+
* These utilities favour convenience over granular control, making them suitable for
|
|
5
|
+
* straightforward integrations where automatically configuring transports is preferable to
|
|
6
|
+
* repeating boilerplate in every application.
|
|
7
7
|
*/
|
|
8
8
|
import { type CreateConfigParameters } from '@wagmi/core';
|
|
9
|
+
/**
|
|
10
|
+
* Options for {@link getDefaultTransports}.
|
|
11
|
+
*/
|
|
9
12
|
type GetDefaultTransportsProps = {
|
|
10
13
|
chains?: CreateConfigParameters['chains'];
|
|
11
14
|
alchemyId?: string;
|
|
12
15
|
infuraId?: string;
|
|
13
16
|
};
|
|
17
|
+
/**
|
|
18
|
+
* Creates a map of Wagmi transports for the provided chains.
|
|
19
|
+
*
|
|
20
|
+
* @param props - Configuration for the generated transports.
|
|
21
|
+
* @param props.chains - Chains that require transports. Defaults to popular EVM chains.
|
|
22
|
+
* @param props.alchemyId - Alchemy API key used to prioritise Alchemy transports when available.
|
|
23
|
+
* @param props.infuraId - Infura API key used to prioritise Infura transports when available.
|
|
24
|
+
* @returns A record mapping chain identifiers to their fallback transport configuration.
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* ```ts
|
|
28
|
+
* import { createConfig } from 'wagmi';
|
|
29
|
+
* import { getDefaultTransports } from '@openfort/openfort-react';
|
|
30
|
+
*
|
|
31
|
+
* const config = createConfig({
|
|
32
|
+
* chains: [mainnet],
|
|
33
|
+
* transports: getDefaultTransports({ alchemyId: process.env.ALCHEMY_ID ?? '' }),
|
|
34
|
+
* });
|
|
35
|
+
* ```
|
|
36
|
+
*/
|
|
14
37
|
export declare const getDefaultTransports: ({ chains, alchemyId, infuraId, }: GetDefaultTransportsProps) => CreateConfigParameters["transports"];
|
|
15
38
|
export {};
|
|
@@ -11,6 +11,69 @@ type CallbackResult = (StoreCredentialsResult & {
|
|
|
11
11
|
type UseAuthCallbackOptions = {
|
|
12
12
|
enabled?: boolean;
|
|
13
13
|
} & OpenfortHookOptions<CallbackResult> & CreateWalletPostAuthOptions;
|
|
14
|
+
/**
|
|
15
|
+
* Hook for handling authentication callbacks from OAuth providers and email verification
|
|
16
|
+
*
|
|
17
|
+
* This hook automatically processes authentication callbacks when the page loads with
|
|
18
|
+
* authentication parameters in the URL. It handles both OAuth provider callbacks
|
|
19
|
+
* (with access tokens) and email verification callbacks (with state tokens).
|
|
20
|
+
* The hook extracts parameters from the URL and automatically calls the appropriate
|
|
21
|
+
* authentication methods, then cleans up the URL parameters.
|
|
22
|
+
*
|
|
23
|
+
* @param options - Optional configuration with callback functions and authentication options
|
|
24
|
+
* @returns Current callback processing state and extracted information
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* ```tsx
|
|
28
|
+
* const authCallback = useAuthCallback({
|
|
29
|
+
* enabled: true,
|
|
30
|
+
* onSuccess: (result) => {
|
|
31
|
+
* if (result.type === 'storeCredentials') {
|
|
32
|
+
* console.log('OAuth callback processed:', result.user);
|
|
33
|
+
* } else if (result.type === 'verifyEmail') {
|
|
34
|
+
* console.log('Email verified:', result.email);
|
|
35
|
+
* }
|
|
36
|
+
* },
|
|
37
|
+
* onError: (error) => console.error('Callback processing failed:', error),
|
|
38
|
+
* recoverWalletAutomatically: true,
|
|
39
|
+
* });
|
|
40
|
+
*
|
|
41
|
+
* // Check callback processing state
|
|
42
|
+
* if (authCallback.isLoading) {
|
|
43
|
+
* console.log('Processing authentication callback...');
|
|
44
|
+
* } else if (authCallback.isError) {
|
|
45
|
+
* console.error('Callback error:', authCallback.error);
|
|
46
|
+
* } else if (authCallback.isSuccess) {
|
|
47
|
+
* console.log('Callback processed successfully');
|
|
48
|
+
* }
|
|
49
|
+
*
|
|
50
|
+
* // Access extracted information
|
|
51
|
+
* if (authCallback.provider) {
|
|
52
|
+
* console.log('Authentication provider:', authCallback.provider);
|
|
53
|
+
* }
|
|
54
|
+
*
|
|
55
|
+
* if (authCallback.email) {
|
|
56
|
+
* console.log('Email from callback:', authCallback.email);
|
|
57
|
+
* }
|
|
58
|
+
*
|
|
59
|
+
* // Manually trigger verification (if needed)
|
|
60
|
+
* const handleManualVerification = async () => {
|
|
61
|
+
* await authCallback.verifyEmail({
|
|
62
|
+
* email: 'user@example.com',
|
|
63
|
+
* state: 'verification-token',
|
|
64
|
+
* });
|
|
65
|
+
* };
|
|
66
|
+
*
|
|
67
|
+
* // Manually store credentials (if needed)
|
|
68
|
+
* const handleManualStore = async () => {
|
|
69
|
+
* await authCallback.storeCredentials({
|
|
70
|
+
* player: 'player-id',
|
|
71
|
+
* accessToken: 'access-token',
|
|
72
|
+
* refreshToken: 'refresh-token',
|
|
73
|
+
* });
|
|
74
|
+
* };
|
|
75
|
+
* ```
|
|
76
|
+
*/
|
|
14
77
|
export declare const useAuthCallback: ({ enabled, ...hookOptions }?: UseAuthCallbackOptions) => {
|
|
15
78
|
email: string | null;
|
|
16
79
|
provider: UIAuthProvider | null;
|
|
@@ -1,16 +1,38 @@
|
|
|
1
1
|
import { UserWallet } from "../useWallets";
|
|
2
|
+
/**
|
|
3
|
+
* Options that control the behaviour of {@link useConnectToWalletPostAuth} when attempting to
|
|
4
|
+
* recover or create an embedded wallet after authentication.
|
|
5
|
+
*/
|
|
2
6
|
export type CreateWalletPostAuthOptions = {
|
|
3
7
|
/**
|
|
4
|
-
*
|
|
5
|
-
*
|
|
8
|
+
* Whether the user should be signed out if automatic wallet creation fails.
|
|
9
|
+
*
|
|
10
|
+
* @defaultValue true
|
|
6
11
|
*/
|
|
7
12
|
logoutOnError?: boolean;
|
|
8
13
|
/**
|
|
9
|
-
*
|
|
10
|
-
*
|
|
14
|
+
* Whether the hook should automatically attempt to recover an existing wallet that
|
|
15
|
+
* supports automatic recovery.
|
|
16
|
+
*
|
|
17
|
+
* @defaultValue true
|
|
11
18
|
*/
|
|
12
19
|
recoverWalletAutomatically?: boolean;
|
|
13
20
|
};
|
|
21
|
+
/**
|
|
22
|
+
* React hook that attempts to recover or create an embedded wallet once a user has authenticated.
|
|
23
|
+
*
|
|
24
|
+
* @returns Helpers that execute the post-authentication wallet connection flow.
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* ```ts
|
|
28
|
+
* const { tryUseWallet } = useConnectToWalletPostAuth();
|
|
29
|
+
*
|
|
30
|
+
* const result = await tryUseWallet({ recoverWalletAutomatically: false });
|
|
31
|
+
* if (!result.wallet) {
|
|
32
|
+
* console.warn('No embedded wallet available after authentication');
|
|
33
|
+
* }
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
14
36
|
export declare const useConnectToWalletPostAuth: () => {
|
|
15
37
|
tryUseWallet: ({ logoutOnError: signOutOnError, recoverWalletAutomatically }: CreateWalletPostAuthOptions) => Promise<{
|
|
16
38
|
wallet?: UserWallet;
|
|
@@ -44,6 +44,77 @@ export type EmailVerificationResult = {
|
|
|
44
44
|
export type UseEmailHookOptions = {
|
|
45
45
|
emailVerificationRedirectTo?: string;
|
|
46
46
|
} & OpenfortHookOptions<EmailAuthResult | EmailVerificationResult> & CreateWalletPostAuthOptions;
|
|
47
|
+
/**
|
|
48
|
+
* Hook for email-based authentication operations
|
|
49
|
+
*
|
|
50
|
+
* This hook manages email authentication flows including sign-in, sign-up, password reset,
|
|
51
|
+
* email verification, and email linking. It handles both password and passwordless authentication
|
|
52
|
+
* and automatically manages wallet connection after successful authentication.
|
|
53
|
+
*
|
|
54
|
+
* @param hookOptions - Optional configuration with callback functions and authentication options
|
|
55
|
+
* @returns Current authentication state with email auth actions
|
|
56
|
+
*
|
|
57
|
+
* @example
|
|
58
|
+
* ```tsx
|
|
59
|
+
* const emailAuth = useEmailAuth({
|
|
60
|
+
* onSignInEmailSuccess: (result) => console.log('Signed in:', result.user),
|
|
61
|
+
* onSignInEmailError: (error) => console.error('Sign-in failed:', error),
|
|
62
|
+
* emailVerificationRedirectTo: 'https://yourapp.com/verify',
|
|
63
|
+
* recoverWalletAutomatically: true,
|
|
64
|
+
* });
|
|
65
|
+
*
|
|
66
|
+
* // Sign up with email and password
|
|
67
|
+
* await emailAuth.signUpEmail({
|
|
68
|
+
* email: 'user@example.com',
|
|
69
|
+
* password: 'securePassword123',
|
|
70
|
+
* name: 'John Doe',
|
|
71
|
+
* });
|
|
72
|
+
*
|
|
73
|
+
* // Sign in with email and password
|
|
74
|
+
* await emailAuth.signInEmail({
|
|
75
|
+
* email: 'user@example.com',
|
|
76
|
+
* password: 'securePassword123',
|
|
77
|
+
* });
|
|
78
|
+
*
|
|
79
|
+
* // Request password reset
|
|
80
|
+
* await emailAuth.requestResetPassword({
|
|
81
|
+
* email: 'user@example.com',
|
|
82
|
+
* });
|
|
83
|
+
*
|
|
84
|
+
* // Reset password with state token
|
|
85
|
+
* await emailAuth.resetPassword({
|
|
86
|
+
* email: 'user@example.com',
|
|
87
|
+
* password: 'newPassword123',
|
|
88
|
+
* state: 'reset-token-from-email',
|
|
89
|
+
* });
|
|
90
|
+
*
|
|
91
|
+
* // Verify email with state token
|
|
92
|
+
* await emailAuth.verifyEmail({
|
|
93
|
+
* email: 'user@example.com',
|
|
94
|
+
* state: 'verification-token-from-email',
|
|
95
|
+
* });
|
|
96
|
+
*
|
|
97
|
+
* // Link email to existing authenticated account
|
|
98
|
+
* await emailAuth.linkEmail({
|
|
99
|
+
* email: 'secondary@example.com',
|
|
100
|
+
* password: 'password123',
|
|
101
|
+
* });
|
|
102
|
+
*
|
|
103
|
+
* // Check authentication state
|
|
104
|
+
* if (emailAuth.isLoading) {
|
|
105
|
+
* console.log('Processing authentication...');
|
|
106
|
+
* } else if (emailAuth.isError) {
|
|
107
|
+
* console.error('Authentication error:', emailAuth.error);
|
|
108
|
+
* } else if (emailAuth.isSuccess) {
|
|
109
|
+
* console.log('Authentication successful');
|
|
110
|
+
* }
|
|
111
|
+
*
|
|
112
|
+
* // Handle email verification requirement
|
|
113
|
+
* if (emailAuth.requiresEmailVerification) {
|
|
114
|
+
* console.log('Please check your email to verify your account');
|
|
115
|
+
* }
|
|
116
|
+
* ```
|
|
117
|
+
*/
|
|
47
118
|
export declare const useEmailAuth: (hookOptions?: UseEmailHookOptions) => {
|
|
48
119
|
requiresEmailVerification: boolean;
|
|
49
120
|
isAwaitingInput: boolean;
|
|
@@ -8,6 +8,65 @@ export type GuestHookResult = {
|
|
|
8
8
|
wallet?: UserWallet;
|
|
9
9
|
};
|
|
10
10
|
export type GuestHookOptions = OpenfortHookOptions<GuestHookResult> & CreateWalletPostAuthOptions;
|
|
11
|
+
/**
|
|
12
|
+
* Hook for guest authentication operations
|
|
13
|
+
*
|
|
14
|
+
* This hook manages guest user authentication, allowing users to create temporary
|
|
15
|
+
* accounts without providing email or other credentials. Guest authentication provides
|
|
16
|
+
* a quick way for users to get started with the application before committing to
|
|
17
|
+
* full registration. After authentication, it automatically handles wallet connection.
|
|
18
|
+
*
|
|
19
|
+
* @param hookOptions - Optional configuration with callback functions and authentication options
|
|
20
|
+
* @returns Current guest authentication state and actions
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* ```tsx
|
|
24
|
+
* const guestAuth = useGuestAuth({
|
|
25
|
+
* onSignUpGuestSuccess: (result) => console.log('Guest user created:', result.user),
|
|
26
|
+
* onSignUpGuestError: (error) => console.error('Guest signup failed:', error),
|
|
27
|
+
* recoverWalletAutomatically: true,
|
|
28
|
+
* logoutOnError: false,
|
|
29
|
+
* });
|
|
30
|
+
*
|
|
31
|
+
* // Sign up as guest user
|
|
32
|
+
* const handleGuestSignup = async () => {
|
|
33
|
+
* try {
|
|
34
|
+
* const result = await guestAuth.signUpGuest();
|
|
35
|
+
* if (result.user) {
|
|
36
|
+
* console.log('Guest user created:', result.user.id);
|
|
37
|
+
* console.log('User wallet:', result.wallet);
|
|
38
|
+
* }
|
|
39
|
+
* } catch (error) {
|
|
40
|
+
* console.error('Guest signup failed:', error);
|
|
41
|
+
* }
|
|
42
|
+
* };
|
|
43
|
+
*
|
|
44
|
+
* // Check authentication state
|
|
45
|
+
* if (guestAuth.isLoading) {
|
|
46
|
+
* console.log('Creating guest account...');
|
|
47
|
+
* } else if (guestAuth.isError) {
|
|
48
|
+
* console.error('Guest auth error:', guestAuth.error);
|
|
49
|
+
* } else if (guestAuth.isSuccess) {
|
|
50
|
+
* console.log('Guest authentication successful');
|
|
51
|
+
* }
|
|
52
|
+
*
|
|
53
|
+
* // Example usage in component
|
|
54
|
+
* return (
|
|
55
|
+
* <div>
|
|
56
|
+
* <button
|
|
57
|
+
* onClick={handleGuestSignup}
|
|
58
|
+
* disabled={guestAuth.isLoading}
|
|
59
|
+
* >
|
|
60
|
+
* {guestAuth.isLoading ? 'Creating Guest Account...' : 'Continue as Guest'}
|
|
61
|
+
* </button>
|
|
62
|
+
*
|
|
63
|
+
* {guestAuth.isError && (
|
|
64
|
+
* <p>Error: {guestAuth.error?.message}</p>
|
|
65
|
+
* )}
|
|
66
|
+
* </div>
|
|
67
|
+
* );
|
|
68
|
+
* ```
|
|
69
|
+
*/
|
|
11
70
|
export declare const useGuestAuth: (hookOptions?: GuestHookOptions) => {
|
|
12
71
|
isLoading: boolean;
|
|
13
72
|
isError: boolean;
|