@b3dotfun/sdk 0.1.69-alpha.16 → 0.1.69-alpha.18
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/cjs/anyspend/constants/rpc.d.ts +1 -1
- package/dist/cjs/anyspend/constants/rpc.js +1 -1
- package/dist/cjs/anyspend/react/components/AnySpendNFT.js +2 -2
- package/dist/cjs/anyspend/react/components/checkout/CheckoutSuccess.js +3 -3
- package/dist/cjs/anyspend/react/components/common/InsufficientDepositPayment.js +2 -2
- package/dist/cjs/anyspend/react/components/common/OrderDetails.js +2 -2
- package/dist/cjs/anyspend/react/components/common/OrderDetailsCollapsible.js +2 -2
- package/dist/cjs/anyspend/react/components/common/TransferCryptoDetails.js +2 -2
- package/dist/cjs/anyspend/utils/chain.js +8 -7
- package/dist/cjs/global-account/better-auth-client.d.ts +1883 -0
- package/dist/cjs/global-account/better-auth-client.js +17 -0
- package/dist/cjs/global-account/react/components/B3Provider/B3ConfigProvider.d.ts +4 -1
- package/dist/cjs/global-account/react/components/B3Provider/B3ConfigProvider.js +2 -1
- package/dist/cjs/global-account/react/components/B3Provider/B3Provider.d.ts +4 -1
- package/dist/cjs/global-account/react/components/B3Provider/B3Provider.js +3 -2
- package/dist/cjs/global-account/react/components/B3Provider/BetterAuthProvider.d.ts +16 -0
- package/dist/cjs/global-account/react/components/B3Provider/BetterAuthProvider.js +120 -0
- package/dist/cjs/global-account/react/components/SignInWithB3/BetterAuthResetPassword.d.ts +21 -0
- package/dist/cjs/global-account/react/components/SignInWithB3/BetterAuthResetPassword.js +67 -0
- package/dist/cjs/global-account/react/components/SignInWithB3/BetterAuthSignIn.d.ts +34 -0
- package/dist/cjs/global-account/react/components/SignInWithB3/BetterAuthSignIn.js +149 -0
- package/dist/cjs/global-account/react/components/SignInWithB3/SignInWithB3Flow.js +9 -3
- package/dist/cjs/global-account/react/components/SignInWithB3/steps/LoginStepBetterAuth.d.ts +6 -0
- package/dist/cjs/global-account/react/components/SignInWithB3/steps/LoginStepBetterAuth.js +123 -0
- package/dist/cjs/global-account/react/components/SignInWithB3/utils/signInUtils.js +5 -1
- package/dist/cjs/global-account/react/components/custom/Button.d.ts +1 -1
- package/dist/cjs/global-account/react/components/index.d.ts +3 -0
- package/dist/cjs/global-account/react/components/index.js +7 -3
- package/dist/cjs/global-account/react/components/ui/button.d.ts +1 -1
- package/dist/cjs/global-account/react/hooks/index.d.ts +1 -0
- package/dist/cjs/global-account/react/hooks/index.js +4 -2
- package/dist/cjs/global-account/react/hooks/useBetterAuth.d.ts +969 -0
- package/dist/cjs/global-account/react/hooks/useBetterAuth.js +142 -0
- package/dist/cjs/shared/constants/chains/b3Chain.d.ts +7 -7
- package/dist/cjs/shared/constants/chains/b3Chain.js +4 -4
- package/dist/cjs/shared/constants/chains/b3Viem.d.ts +6 -0
- package/dist/cjs/shared/constants/chains/b3Viem.js +19 -0
- package/dist/cjs/shared/constants/chains/supported.d.ts +1 -1
- package/dist/cjs/shared/generated/chain-networks.json +2 -2
- package/dist/cjs/shared/utils/chains.d.ts +1 -1
- package/dist/cjs/shared/utils/chains.js +2 -2
- package/dist/esm/anyspend/constants/rpc.d.ts +1 -1
- package/dist/esm/anyspend/constants/rpc.js +1 -1
- package/dist/esm/anyspend/react/components/AnySpendNFT.js +2 -2
- package/dist/esm/anyspend/react/components/checkout/CheckoutSuccess.js +3 -3
- package/dist/esm/anyspend/react/components/common/InsufficientDepositPayment.js +2 -2
- package/dist/esm/anyspend/react/components/common/OrderDetails.js +2 -2
- package/dist/esm/anyspend/react/components/common/OrderDetailsCollapsible.js +2 -2
- package/dist/esm/anyspend/react/components/common/TransferCryptoDetails.js +2 -2
- package/dist/esm/anyspend/utils/chain.js +10 -9
- package/dist/esm/global-account/better-auth-client.d.ts +1883 -0
- package/dist/esm/global-account/better-auth-client.js +13 -0
- package/dist/esm/global-account/react/components/B3Provider/B3ConfigProvider.d.ts +4 -1
- package/dist/esm/global-account/react/components/B3Provider/B3ConfigProvider.js +2 -1
- package/dist/esm/global-account/react/components/B3Provider/B3Provider.d.ts +4 -1
- package/dist/esm/global-account/react/components/B3Provider/B3Provider.js +3 -2
- package/dist/esm/global-account/react/components/B3Provider/BetterAuthProvider.d.ts +16 -0
- package/dist/esm/global-account/react/components/B3Provider/BetterAuthProvider.js +115 -0
- package/dist/esm/global-account/react/components/SignInWithB3/BetterAuthResetPassword.d.ts +21 -0
- package/dist/esm/global-account/react/components/SignInWithB3/BetterAuthResetPassword.js +64 -0
- package/dist/esm/global-account/react/components/SignInWithB3/BetterAuthSignIn.d.ts +34 -0
- package/dist/esm/global-account/react/components/SignInWithB3/BetterAuthSignIn.js +146 -0
- package/dist/esm/global-account/react/components/SignInWithB3/SignInWithB3Flow.js +9 -3
- package/dist/esm/global-account/react/components/SignInWithB3/steps/LoginStepBetterAuth.d.ts +6 -0
- package/dist/esm/global-account/react/components/SignInWithB3/steps/LoginStepBetterAuth.js +120 -0
- package/dist/esm/global-account/react/components/SignInWithB3/utils/signInUtils.js +5 -1
- package/dist/esm/global-account/react/components/custom/Button.d.ts +1 -1
- package/dist/esm/global-account/react/components/index.d.ts +3 -0
- package/dist/esm/global-account/react/components/index.js +2 -0
- package/dist/esm/global-account/react/components/ui/button.d.ts +1 -1
- package/dist/esm/global-account/react/hooks/index.d.ts +1 -0
- package/dist/esm/global-account/react/hooks/index.js +1 -0
- package/dist/esm/global-account/react/hooks/useBetterAuth.d.ts +969 -0
- package/dist/esm/global-account/react/hooks/useBetterAuth.js +136 -0
- package/dist/esm/shared/constants/chains/b3Chain.d.ts +7 -7
- package/dist/esm/shared/constants/chains/b3Chain.js +4 -4
- package/dist/esm/shared/constants/chains/b3Viem.d.ts +6 -0
- package/dist/esm/shared/constants/chains/b3Viem.js +16 -0
- package/dist/esm/shared/constants/chains/supported.d.ts +1 -1
- package/dist/esm/shared/generated/chain-networks.json +2 -2
- package/dist/esm/shared/utils/chains.d.ts +1 -1
- package/dist/esm/shared/utils/chains.js +2 -2
- package/dist/styles/index.css +1 -1
- package/dist/types/anyspend/constants/rpc.d.ts +1 -1
- package/dist/types/global-account/better-auth-client.d.ts +1883 -0
- package/dist/types/global-account/react/components/B3Provider/B3ConfigProvider.d.ts +4 -1
- package/dist/types/global-account/react/components/B3Provider/B3Provider.d.ts +4 -1
- package/dist/types/global-account/react/components/B3Provider/BetterAuthProvider.d.ts +16 -0
- package/dist/types/global-account/react/components/SignInWithB3/BetterAuthResetPassword.d.ts +21 -0
- package/dist/types/global-account/react/components/SignInWithB3/BetterAuthSignIn.d.ts +34 -0
- package/dist/types/global-account/react/components/SignInWithB3/steps/LoginStepBetterAuth.d.ts +6 -0
- package/dist/types/global-account/react/components/custom/Button.d.ts +1 -1
- package/dist/types/global-account/react/components/index.d.ts +3 -0
- package/dist/types/global-account/react/components/ui/button.d.ts +1 -1
- package/dist/types/global-account/react/hooks/index.d.ts +1 -0
- package/dist/types/global-account/react/hooks/useBetterAuth.d.ts +969 -0
- package/dist/types/shared/constants/chains/b3Chain.d.ts +7 -7
- package/dist/types/shared/constants/chains/b3Viem.d.ts +6 -0
- package/dist/types/shared/constants/chains/supported.d.ts +1 -1
- package/dist/types/shared/utils/chains.d.ts +1 -1
- package/package.json +2 -1
- package/src/anyspend/constants/rpc.ts +2 -1
- package/src/anyspend/react/components/AnySpendNFT.tsx +2 -2
- package/src/anyspend/react/components/checkout/CheckoutSuccess.tsx +3 -3
- package/src/anyspend/react/components/common/InsufficientDepositPayment.tsx +2 -2
- package/src/anyspend/react/components/common/OrderDetails.tsx +2 -2
- package/src/anyspend/react/components/common/OrderDetailsCollapsible.tsx +4 -4
- package/src/anyspend/react/components/common/TransferCryptoDetails.tsx +2 -2
- package/src/anyspend/utils/chain.ts +9 -9
- package/src/global-account/better-auth-client.ts +17 -0
- package/src/global-account/react/components/B3Provider/B3ConfigProvider.tsx +6 -0
- package/src/global-account/react/components/B3Provider/B3Provider.tsx +15 -5
- package/src/global-account/react/components/B3Provider/BetterAuthProvider.tsx +127 -0
- package/src/global-account/react/components/SignInWithB3/BetterAuthResetPassword.tsx +146 -0
- package/src/global-account/react/components/SignInWithB3/BetterAuthSignIn.tsx +375 -0
- package/src/global-account/react/components/SignInWithB3/SignInWithB3Flow.tsx +9 -3
- package/src/global-account/react/components/SignInWithB3/steps/LoginStepBetterAuth.tsx +263 -0
- package/src/global-account/react/components/SignInWithB3/utils/signInUtils.ts +5 -1
- package/src/global-account/react/components/index.ts +3 -0
- package/src/global-account/react/hooks/index.ts +1 -0
- package/src/global-account/react/hooks/useBetterAuth.ts +177 -0
- package/src/shared/constants/chains/b3Chain.ts +5 -5
- package/src/shared/constants/chains/b3Viem.ts +18 -0
- package/src/shared/generated/chain-networks.json +2 -2
- package/src/shared/utils/chains.ts +3 -2
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
import { Button, Input } from "@b3dotfun/sdk/global-account/react";
|
|
2
|
+
import { debugB3React } from "@b3dotfun/sdk/shared/utils/debug";
|
|
3
|
+
import { useState } from "react";
|
|
4
|
+
import { useBetterAuth } from "../../hooks/useBetterAuth";
|
|
5
|
+
|
|
6
|
+
const debug = debugB3React("BetterAuthResetPassword");
|
|
7
|
+
|
|
8
|
+
export interface BetterAuthResetPasswordProps {
|
|
9
|
+
/** The reset token from the URL query param */
|
|
10
|
+
token: string;
|
|
11
|
+
/** Called after password is successfully reset */
|
|
12
|
+
onSuccess?: () => void;
|
|
13
|
+
/** Called on error */
|
|
14
|
+
onError?: (error: Error) => void;
|
|
15
|
+
/** Optional class name */
|
|
16
|
+
className?: string;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Standalone reset password form. Render this on your reset password page.
|
|
21
|
+
* Reads the token from props (extract it from the URL query string).
|
|
22
|
+
*
|
|
23
|
+
* Usage:
|
|
24
|
+
* ```tsx
|
|
25
|
+
* const token = new URLSearchParams(window.location.search).get("token");
|
|
26
|
+
* <BetterAuthResetPassword token={token} onSuccess={() => navigate("/login")} />
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
export function BetterAuthResetPassword({ token, onSuccess, onError, className }: BetterAuthResetPasswordProps) {
|
|
30
|
+
const { resetPassword } = useBetterAuth();
|
|
31
|
+
|
|
32
|
+
const [password, setPassword] = useState("");
|
|
33
|
+
const [confirmPassword, setConfirmPassword] = useState("");
|
|
34
|
+
const [isLoading, setIsLoading] = useState(false);
|
|
35
|
+
const [error, setError] = useState<string | null>(null);
|
|
36
|
+
const [success, setSuccess] = useState(false);
|
|
37
|
+
|
|
38
|
+
const handleSubmit = async () => {
|
|
39
|
+
if (!password) {
|
|
40
|
+
setError("Please enter a new password");
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
if (password.length < 8) {
|
|
45
|
+
setError("Password must be at least 8 characters");
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
if (password !== confirmPassword) {
|
|
50
|
+
setError("Passwords do not match");
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
try {
|
|
55
|
+
setIsLoading(true);
|
|
56
|
+
setError(null);
|
|
57
|
+
await resetPassword(password, token);
|
|
58
|
+
setSuccess(true);
|
|
59
|
+
debug("Password reset successful");
|
|
60
|
+
onSuccess?.();
|
|
61
|
+
} catch (err) {
|
|
62
|
+
const message = err instanceof Error ? err.message : "Password reset failed";
|
|
63
|
+
setError(message);
|
|
64
|
+
debug("Password reset failed", err);
|
|
65
|
+
onError?.(err as Error);
|
|
66
|
+
} finally {
|
|
67
|
+
setPassword("");
|
|
68
|
+
setConfirmPassword("");
|
|
69
|
+
setIsLoading(false);
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
if (!token) {
|
|
74
|
+
return (
|
|
75
|
+
<div className={`w-full max-w-[400px] px-6 text-center ${className || ""}`}>
|
|
76
|
+
<p className="text-sm text-red-500">Invalid or missing reset token.</p>
|
|
77
|
+
</div>
|
|
78
|
+
);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
return (
|
|
82
|
+
<div className={`w-full max-w-[400px] px-6 ${className || ""}`}>
|
|
83
|
+
<div className="mb-10 text-center">
|
|
84
|
+
<h1 className="text-[28px] font-semibold tracking-tight text-gray-900 dark:text-gray-100">
|
|
85
|
+
{success ? "Password reset" : "Set new password"}
|
|
86
|
+
</h1>
|
|
87
|
+
<p className="mt-3 text-[15px] text-gray-500 dark:text-gray-400">
|
|
88
|
+
{success ? "Your password has been updated." : "Enter your new password below."}
|
|
89
|
+
</p>
|
|
90
|
+
</div>
|
|
91
|
+
|
|
92
|
+
{success ? (
|
|
93
|
+
<div className="space-y-4 text-center">
|
|
94
|
+
<div className="mx-auto flex h-12 w-12 items-center justify-center rounded-full bg-green-100">
|
|
95
|
+
<svg className="h-6 w-6 text-green-600" fill="none" viewBox="0 0 24 24" stroke="currentColor">
|
|
96
|
+
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M5 13l4 4L19 7" />
|
|
97
|
+
</svg>
|
|
98
|
+
</div>
|
|
99
|
+
</div>
|
|
100
|
+
) : (
|
|
101
|
+
<div className="space-y-5">
|
|
102
|
+
<div>
|
|
103
|
+
<label className="mb-2 block text-xs font-medium uppercase tracking-wide text-gray-700 dark:text-gray-300">
|
|
104
|
+
New password
|
|
105
|
+
</label>
|
|
106
|
+
<Input
|
|
107
|
+
type="password"
|
|
108
|
+
placeholder="At least 8 characters"
|
|
109
|
+
value={password}
|
|
110
|
+
onChange={e => setPassword(e.target.value)}
|
|
111
|
+
disabled={isLoading}
|
|
112
|
+
className="h-11 px-4 text-[15px]"
|
|
113
|
+
/>
|
|
114
|
+
</div>
|
|
115
|
+
|
|
116
|
+
<div>
|
|
117
|
+
<label className="mb-2 block text-xs font-medium uppercase tracking-wide text-gray-700 dark:text-gray-300">
|
|
118
|
+
Confirm password
|
|
119
|
+
</label>
|
|
120
|
+
<Input
|
|
121
|
+
type="password"
|
|
122
|
+
placeholder="Repeat your password"
|
|
123
|
+
value={confirmPassword}
|
|
124
|
+
onChange={e => setConfirmPassword(e.target.value)}
|
|
125
|
+
disabled={isLoading}
|
|
126
|
+
onKeyDown={e => {
|
|
127
|
+
if (e.key === "Enter") handleSubmit();
|
|
128
|
+
}}
|
|
129
|
+
className="h-11 px-4 text-[15px]"
|
|
130
|
+
/>
|
|
131
|
+
</div>
|
|
132
|
+
|
|
133
|
+
{error && <p className="text-sm text-red-500">{error}</p>}
|
|
134
|
+
|
|
135
|
+
<Button
|
|
136
|
+
onClick={handleSubmit}
|
|
137
|
+
disabled={isLoading}
|
|
138
|
+
className="h-11 w-full bg-gray-900 text-[15px] font-medium text-white hover:bg-gray-800 dark:bg-white dark:text-gray-900 dark:hover:bg-gray-100"
|
|
139
|
+
>
|
|
140
|
+
{isLoading ? "Resetting..." : "Reset password"}
|
|
141
|
+
</Button>
|
|
142
|
+
</div>
|
|
143
|
+
)}
|
|
144
|
+
</div>
|
|
145
|
+
);
|
|
146
|
+
}
|
|
@@ -0,0 +1,375 @@
|
|
|
1
|
+
import { Button, Input, useAuthStore } from "@b3dotfun/sdk/global-account/react";
|
|
2
|
+
import { debugB3React } from "@b3dotfun/sdk/shared/utils/debug";
|
|
3
|
+
import { useState } from "react";
|
|
4
|
+
import { type BetterAuthSocialProvider, useBetterAuth } from "../../hooks/useBetterAuth";
|
|
5
|
+
import { strategyIcons, strategyLabels } from "./utils/signInUtils";
|
|
6
|
+
|
|
7
|
+
const debug = debugB3React("BetterAuthSignIn");
|
|
8
|
+
const EMAIL_REGEX = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
|
|
9
|
+
|
|
10
|
+
type SocialProviderConfig = { id: BetterAuthSocialProvider; label: string };
|
|
11
|
+
|
|
12
|
+
const DEFAULT_SOCIAL_PROVIDERS: SocialProviderConfig[] = [
|
|
13
|
+
{ id: "google", label: "Google" },
|
|
14
|
+
{ id: "github", label: "GitHub" },
|
|
15
|
+
{ id: "discord", label: "Discord" },
|
|
16
|
+
{ id: "microsoft", label: "Microsoft" },
|
|
17
|
+
{ id: "slack", label: "Slack" },
|
|
18
|
+
];
|
|
19
|
+
|
|
20
|
+
export interface BetterAuthSignInProps {
|
|
21
|
+
/** Title displayed above the form. Default: "Welcome back" for sign-in, "Create an account" for sign-up */
|
|
22
|
+
title?: string;
|
|
23
|
+
/** Subtitle displayed below the title */
|
|
24
|
+
subtitle?: string;
|
|
25
|
+
/** Which social providers to show. Defaults to all. Pass empty array to hide. */
|
|
26
|
+
socialProviders?: BetterAuthSocialProvider[];
|
|
27
|
+
/** Show email/password form. Default: true */
|
|
28
|
+
showEmail?: boolean;
|
|
29
|
+
/** URL to redirect to after password reset link is clicked. Token is appended as ?token=... */
|
|
30
|
+
passwordResetRedirectTo?: string;
|
|
31
|
+
/** Called after successful authentication */
|
|
32
|
+
onSuccess?: () => void;
|
|
33
|
+
/** Called on authentication error */
|
|
34
|
+
onError?: (error: Error) => void;
|
|
35
|
+
/** Optional class name for the root container */
|
|
36
|
+
className?: string;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Standalone inline sign-in component for Better Auth.
|
|
41
|
+
*
|
|
42
|
+
* Renders directly — no modal, no button wrapper. Designed for full-page
|
|
43
|
+
* sign-in layouts (e.g., B3OS web with branding on the left, form on the right).
|
|
44
|
+
*
|
|
45
|
+
* Usage:
|
|
46
|
+
* ```tsx
|
|
47
|
+
* <BetterAuthSignIn
|
|
48
|
+
* socialProviders={["google", "github"]}
|
|
49
|
+
* onSuccess={() => router.push("/dashboard")}
|
|
50
|
+
* />
|
|
51
|
+
* ```
|
|
52
|
+
*/
|
|
53
|
+
export function BetterAuthSignIn({
|
|
54
|
+
title,
|
|
55
|
+
subtitle = "Enter your credentials to access your account",
|
|
56
|
+
socialProviders = DEFAULT_SOCIAL_PROVIDERS.map(p => p.id),
|
|
57
|
+
showEmail = true,
|
|
58
|
+
passwordResetRedirectTo,
|
|
59
|
+
onSuccess,
|
|
60
|
+
onError,
|
|
61
|
+
className,
|
|
62
|
+
}: BetterAuthSignInProps) {
|
|
63
|
+
const { signInWithEmail, signUpWithEmail, signInWithSocial, requestPasswordReset } = useBetterAuth();
|
|
64
|
+
const isAuthenticated = useAuthStore(state => state.isAuthenticated);
|
|
65
|
+
|
|
66
|
+
const [mode, setMode] = useState<"sign-in" | "sign-up" | "forgot-password">("sign-in");
|
|
67
|
+
const [email, setEmail] = useState("");
|
|
68
|
+
const [password, setPassword] = useState("");
|
|
69
|
+
const [name, setName] = useState("");
|
|
70
|
+
const [isLoading, setIsLoading] = useState(false);
|
|
71
|
+
const [loadingProvider, setLoadingProvider] = useState<string | null>(null);
|
|
72
|
+
const [error, setError] = useState<string | null>(null);
|
|
73
|
+
const [resetEmailSent, setResetEmailSent] = useState(false);
|
|
74
|
+
|
|
75
|
+
const resolvedTitle =
|
|
76
|
+
title ||
|
|
77
|
+
(mode === "forgot-password" ? "Reset password" : mode === "sign-in" ? "Welcome back" : "Create an account");
|
|
78
|
+
|
|
79
|
+
const resolvedSubtitle =
|
|
80
|
+
mode === "forgot-password"
|
|
81
|
+
? "Enter your email and we'll send you a reset link"
|
|
82
|
+
: subtitle || "Enter your credentials to access your account";
|
|
83
|
+
|
|
84
|
+
const handleForgotPassword = async () => {
|
|
85
|
+
const normalizedEmail = email.trim().toLowerCase();
|
|
86
|
+
|
|
87
|
+
if (!EMAIL_REGEX.test(normalizedEmail)) {
|
|
88
|
+
setError("Please enter a valid email address");
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
try {
|
|
93
|
+
setIsLoading(true);
|
|
94
|
+
setError(null);
|
|
95
|
+
await requestPasswordReset(normalizedEmail, passwordResetRedirectTo);
|
|
96
|
+
setResetEmailSent(true);
|
|
97
|
+
} catch (err) {
|
|
98
|
+
const message = err instanceof Error ? err.message : "Failed to send reset email";
|
|
99
|
+
setError(message);
|
|
100
|
+
} finally {
|
|
101
|
+
setIsLoading(false);
|
|
102
|
+
}
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
const providers: SocialProviderConfig[] = socialProviders
|
|
106
|
+
.map(id => DEFAULT_SOCIAL_PROVIDERS.find(p => p.id === id))
|
|
107
|
+
.filter((p): p is SocialProviderConfig => !!p);
|
|
108
|
+
|
|
109
|
+
if (isAuthenticated) {
|
|
110
|
+
return null;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
const handleEmailSubmit = async () => {
|
|
114
|
+
const normalizedEmail = email.trim().toLowerCase();
|
|
115
|
+
|
|
116
|
+
if (!EMAIL_REGEX.test(normalizedEmail)) {
|
|
117
|
+
setError("Please enter a valid email address");
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
if (!password) {
|
|
122
|
+
setError("Please enter a password");
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
if (mode === "sign-up" && !name.trim()) {
|
|
127
|
+
setError("Please enter your name");
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
try {
|
|
132
|
+
setIsLoading(true);
|
|
133
|
+
setError(null);
|
|
134
|
+
|
|
135
|
+
if (mode === "sign-up") {
|
|
136
|
+
await signUpWithEmail(normalizedEmail, password, name.trim());
|
|
137
|
+
} else {
|
|
138
|
+
await signInWithEmail(normalizedEmail, password);
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
debug("Auth successful");
|
|
142
|
+
onSuccess?.();
|
|
143
|
+
} catch (err) {
|
|
144
|
+
const message = err instanceof Error ? err.message : "Authentication failed";
|
|
145
|
+
setError(message);
|
|
146
|
+
debug("Auth failed", err);
|
|
147
|
+
onError?.(err as Error);
|
|
148
|
+
} finally {
|
|
149
|
+
setPassword("");
|
|
150
|
+
setIsLoading(false);
|
|
151
|
+
}
|
|
152
|
+
};
|
|
153
|
+
|
|
154
|
+
const handleSocialSignIn = async (provider: BetterAuthSocialProvider) => {
|
|
155
|
+
try {
|
|
156
|
+
setIsLoading(true);
|
|
157
|
+
setLoadingProvider(provider);
|
|
158
|
+
setError(null);
|
|
159
|
+
await signInWithSocial(provider);
|
|
160
|
+
} catch (err) {
|
|
161
|
+
const message = err instanceof Error ? err.message : `Sign in failed`;
|
|
162
|
+
setError(message);
|
|
163
|
+
onError?.(err as Error);
|
|
164
|
+
setIsLoading(false);
|
|
165
|
+
setLoadingProvider(null);
|
|
166
|
+
}
|
|
167
|
+
};
|
|
168
|
+
|
|
169
|
+
return (
|
|
170
|
+
<div className={`w-full max-w-[400px] px-6 ${className || ""}`}>
|
|
171
|
+
{/* Header */}
|
|
172
|
+
<div className="mb-10 text-center">
|
|
173
|
+
<h1 className="text-[28px] font-semibold tracking-tight text-gray-900 dark:text-gray-100">{resolvedTitle}</h1>
|
|
174
|
+
<p className="mt-3 text-[15px] text-gray-500 dark:text-gray-400">{resolvedSubtitle}</p>
|
|
175
|
+
</div>
|
|
176
|
+
|
|
177
|
+
{/* Forgot password view */}
|
|
178
|
+
{mode === "forgot-password" && (
|
|
179
|
+
<div className="space-y-5">
|
|
180
|
+
{resetEmailSent ? (
|
|
181
|
+
<div className="space-y-4 text-center">
|
|
182
|
+
<div className="mx-auto flex h-12 w-12 items-center justify-center rounded-full bg-green-100">
|
|
183
|
+
<svg className="h-6 w-6 text-green-600" fill="none" viewBox="0 0 24 24" stroke="currentColor">
|
|
184
|
+
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M5 13l4 4L19 7" />
|
|
185
|
+
</svg>
|
|
186
|
+
</div>
|
|
187
|
+
<p className="text-[15px] text-gray-600 dark:text-gray-300">Check your email for a reset link.</p>
|
|
188
|
+
</div>
|
|
189
|
+
) : (
|
|
190
|
+
<>
|
|
191
|
+
<div>
|
|
192
|
+
<label className="mb-2 block text-xs font-medium uppercase tracking-wide text-gray-700 dark:text-gray-300">
|
|
193
|
+
Email
|
|
194
|
+
</label>
|
|
195
|
+
<Input
|
|
196
|
+
type="email"
|
|
197
|
+
placeholder="name@company.com"
|
|
198
|
+
value={email}
|
|
199
|
+
onChange={e => setEmail(e.target.value)}
|
|
200
|
+
disabled={isLoading}
|
|
201
|
+
onKeyDown={e => {
|
|
202
|
+
if (e.key === "Enter") handleForgotPassword();
|
|
203
|
+
}}
|
|
204
|
+
className="h-11 px-4 text-[15px]"
|
|
205
|
+
/>
|
|
206
|
+
</div>
|
|
207
|
+
|
|
208
|
+
{error && <p className="text-sm text-red-500">{error}</p>}
|
|
209
|
+
|
|
210
|
+
<Button
|
|
211
|
+
onClick={handleForgotPassword}
|
|
212
|
+
disabled={isLoading}
|
|
213
|
+
className="h-11 w-full bg-gray-900 text-[15px] font-medium text-white hover:bg-gray-800 dark:bg-white dark:text-gray-900 dark:hover:bg-gray-100"
|
|
214
|
+
>
|
|
215
|
+
{isLoading ? "Sending..." : "Send reset link"}
|
|
216
|
+
</Button>
|
|
217
|
+
</>
|
|
218
|
+
)}
|
|
219
|
+
|
|
220
|
+
<p className="mt-8 text-center text-[14px] text-gray-500 dark:text-gray-400">
|
|
221
|
+
<button
|
|
222
|
+
onClick={() => {
|
|
223
|
+
setMode("sign-in");
|
|
224
|
+
setError(null);
|
|
225
|
+
setResetEmailSent(false);
|
|
226
|
+
}}
|
|
227
|
+
className="font-medium text-blue-600 hover:text-blue-500 dark:text-blue-400"
|
|
228
|
+
>
|
|
229
|
+
Back to sign in
|
|
230
|
+
</button>
|
|
231
|
+
</p>
|
|
232
|
+
</div>
|
|
233
|
+
)}
|
|
234
|
+
|
|
235
|
+
{/* Email/Password form */}
|
|
236
|
+
{showEmail && mode !== "forgot-password" && (
|
|
237
|
+
<div className="space-y-5">
|
|
238
|
+
{mode === "sign-up" && (
|
|
239
|
+
<div>
|
|
240
|
+
<label className="mb-2 block text-xs font-medium uppercase tracking-wide text-gray-700 dark:text-gray-300">
|
|
241
|
+
Name
|
|
242
|
+
</label>
|
|
243
|
+
<Input
|
|
244
|
+
type="text"
|
|
245
|
+
placeholder="Your name"
|
|
246
|
+
value={name}
|
|
247
|
+
onChange={e => setName(e.target.value)}
|
|
248
|
+
disabled={isLoading}
|
|
249
|
+
className="h-11 px-4 text-[15px]"
|
|
250
|
+
/>
|
|
251
|
+
</div>
|
|
252
|
+
)}
|
|
253
|
+
|
|
254
|
+
<div>
|
|
255
|
+
<label className="mb-2 block text-xs font-medium uppercase tracking-wide text-gray-700 dark:text-gray-300">
|
|
256
|
+
Email
|
|
257
|
+
</label>
|
|
258
|
+
<Input
|
|
259
|
+
type="email"
|
|
260
|
+
placeholder="name@company.com"
|
|
261
|
+
value={email}
|
|
262
|
+
onChange={e => setEmail(e.target.value)}
|
|
263
|
+
disabled={isLoading}
|
|
264
|
+
className="h-11 px-4 text-[15px]"
|
|
265
|
+
/>
|
|
266
|
+
</div>
|
|
267
|
+
|
|
268
|
+
<div>
|
|
269
|
+
<div className="mb-2 flex items-center justify-between">
|
|
270
|
+
<label className="block text-xs font-medium uppercase tracking-wide text-gray-700 dark:text-gray-300">
|
|
271
|
+
Password
|
|
272
|
+
</label>
|
|
273
|
+
{mode === "sign-in" && (
|
|
274
|
+
<button
|
|
275
|
+
type="button"
|
|
276
|
+
onClick={() => {
|
|
277
|
+
setMode("forgot-password");
|
|
278
|
+
setError(null);
|
|
279
|
+
}}
|
|
280
|
+
className="text-xs font-medium text-blue-600 hover:text-blue-500 dark:text-blue-400"
|
|
281
|
+
>
|
|
282
|
+
Forgot password?
|
|
283
|
+
</button>
|
|
284
|
+
)}
|
|
285
|
+
</div>
|
|
286
|
+
<Input
|
|
287
|
+
type="password"
|
|
288
|
+
placeholder="Password"
|
|
289
|
+
value={password}
|
|
290
|
+
onChange={e => setPassword(e.target.value)}
|
|
291
|
+
disabled={isLoading}
|
|
292
|
+
onKeyDown={e => {
|
|
293
|
+
if (e.key === "Enter") handleEmailSubmit();
|
|
294
|
+
}}
|
|
295
|
+
className="h-11 px-4 text-[15px]"
|
|
296
|
+
/>
|
|
297
|
+
</div>
|
|
298
|
+
|
|
299
|
+
{error && <p className="text-sm text-red-500">{error}</p>}
|
|
300
|
+
|
|
301
|
+
<Button
|
|
302
|
+
onClick={handleEmailSubmit}
|
|
303
|
+
disabled={isLoading}
|
|
304
|
+
className="h-11 w-full bg-gray-900 text-[15px] font-medium text-white hover:bg-gray-800 dark:bg-white dark:text-gray-900 dark:hover:bg-gray-100"
|
|
305
|
+
>
|
|
306
|
+
{isLoading ? "Loading..." : mode === "sign-in" ? "Sign in" : "Sign up"}
|
|
307
|
+
</Button>
|
|
308
|
+
</div>
|
|
309
|
+
)}
|
|
310
|
+
|
|
311
|
+
{/* Social providers */}
|
|
312
|
+
{providers.length > 0 && mode !== "forgot-password" && (
|
|
313
|
+
<>
|
|
314
|
+
{showEmail && (
|
|
315
|
+
<div className="my-8 flex items-center gap-4">
|
|
316
|
+
<div className="h-px flex-1 bg-gray-200 dark:bg-gray-700" />
|
|
317
|
+
<span className="text-xs text-gray-400">Or continue with</span>
|
|
318
|
+
<div className="h-px flex-1 bg-gray-200 dark:bg-gray-700" />
|
|
319
|
+
</div>
|
|
320
|
+
)}
|
|
321
|
+
|
|
322
|
+
<div className="space-y-4">
|
|
323
|
+
{providers.map(provider => {
|
|
324
|
+
const icon = strategyIcons[provider.id];
|
|
325
|
+
const label = strategyLabels[provider.id] || provider.label;
|
|
326
|
+
|
|
327
|
+
const isProviderLoading = loadingProvider === provider.id;
|
|
328
|
+
|
|
329
|
+
return (
|
|
330
|
+
<button
|
|
331
|
+
key={provider.id}
|
|
332
|
+
onClick={() => handleSocialSignIn(provider.id)}
|
|
333
|
+
disabled={isLoading}
|
|
334
|
+
style={{ paddingTop: "12px", paddingBottom: "12px" }}
|
|
335
|
+
className="flex w-full items-center justify-center gap-3 rounded-lg border border-gray-200 bg-white px-4 text-[14px] font-medium text-gray-700 transition-colors hover:bg-gray-50 disabled:opacity-50 dark:border-gray-700 dark:bg-gray-800 dark:text-gray-200 dark:hover:bg-gray-700"
|
|
336
|
+
>
|
|
337
|
+
{isProviderLoading ? (
|
|
338
|
+
<svg className="h-5 w-5 animate-spin text-gray-400" viewBox="0 0 24 24" fill="none">
|
|
339
|
+
<circle className="opacity-25" cx="12" cy="12" r="10" stroke="currentColor" strokeWidth="4" />
|
|
340
|
+
<path
|
|
341
|
+
className="opacity-75"
|
|
342
|
+
fill="currentColor"
|
|
343
|
+
d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4z"
|
|
344
|
+
/>
|
|
345
|
+
</svg>
|
|
346
|
+
) : (
|
|
347
|
+
icon && <img src={icon} alt="" className="h-5 w-5" />
|
|
348
|
+
)}
|
|
349
|
+
<span>{isProviderLoading ? "Redirecting..." : label}</span>
|
|
350
|
+
</button>
|
|
351
|
+
);
|
|
352
|
+
})}
|
|
353
|
+
</div>
|
|
354
|
+
</>
|
|
355
|
+
)}
|
|
356
|
+
|
|
357
|
+
{/* Toggle sign-in / sign-up */}
|
|
358
|
+
{showEmail && mode !== "forgot-password" && (
|
|
359
|
+
<p className="mt-8 text-center text-[14px] text-gray-500 dark:text-gray-400">
|
|
360
|
+
{mode === "sign-in" ? "Don't have an account? " : "Already have an account? "}
|
|
361
|
+
<button
|
|
362
|
+
onClick={() => {
|
|
363
|
+
setMode(mode === "sign-in" ? "sign-up" : "sign-in");
|
|
364
|
+
setError(null);
|
|
365
|
+
}}
|
|
366
|
+
disabled={isLoading}
|
|
367
|
+
className="font-medium text-blue-600 hover:text-blue-500 dark:text-blue-400"
|
|
368
|
+
>
|
|
369
|
+
{mode === "sign-in" ? "Sign up" : "Sign in"}
|
|
370
|
+
</button>
|
|
371
|
+
</p>
|
|
372
|
+
)}
|
|
373
|
+
</div>
|
|
374
|
+
);
|
|
375
|
+
}
|
|
@@ -7,6 +7,7 @@ import {
|
|
|
7
7
|
useGetAllTWSigners,
|
|
8
8
|
useModalStore,
|
|
9
9
|
} from "@b3dotfun/sdk/global-account/react";
|
|
10
|
+
import { LoginStepBetterAuth } from "./steps/LoginStepBetterAuth";
|
|
10
11
|
import { debugB3React } from "@b3dotfun/sdk/shared/utils/debug";
|
|
11
12
|
import { useCallback, useEffect, useRef, useState } from "react";
|
|
12
13
|
import { useActiveAccount } from "thirdweb/react";
|
|
@@ -34,7 +35,7 @@ export function SignInWithB3Flow({
|
|
|
34
35
|
source = "signInWithB3Button",
|
|
35
36
|
signersEnabled = false,
|
|
36
37
|
}: SignInWithB3ModalProps) {
|
|
37
|
-
const { automaticallySetFirstEoa } = useB3Config();
|
|
38
|
+
const { automaticallySetFirstEoa, authStrategy } = useB3Config();
|
|
38
39
|
// skipAutoConnect: this component intentionally logs out on mount to show a fresh login screen.
|
|
39
40
|
// AuthenticationProvider is the sole owner of useAutoConnect to avoid competing auth cycles.
|
|
40
41
|
const { user, logout } = useAuthentication(partnerId, { skipAutoConnect: true });
|
|
@@ -42,10 +43,13 @@ export function SignInWithB3Flow({
|
|
|
42
43
|
// Tracks whether the pre-login logout has finished.
|
|
43
44
|
// We must not render ConnectEmbed until logout (wallet disconnect) completes,
|
|
44
45
|
// otherwise the wallet state disrupts ConnectEmbed causing a blank modal.
|
|
45
|
-
const [readyToShowLogin, setReadyToShowLogin] = useState(
|
|
46
|
+
const [readyToShowLogin, setReadyToShowLogin] = useState(
|
|
47
|
+
source === "requestPermissions" || authStrategy === "better-auth",
|
|
48
|
+
);
|
|
46
49
|
const hasLoggedOutRef = useRef(false);
|
|
47
50
|
useEffect(() => {
|
|
48
51
|
if (hasLoggedOutRef.current) return;
|
|
52
|
+
if (authStrategy === "better-auth") return;
|
|
49
53
|
if (source !== "requestPermissions") {
|
|
50
54
|
debug("Logging out before login");
|
|
51
55
|
hasLoggedOutRef.current = true;
|
|
@@ -53,7 +57,7 @@ export function SignInWithB3Flow({
|
|
|
53
57
|
setReadyToShowLogin(true);
|
|
54
58
|
});
|
|
55
59
|
}
|
|
56
|
-
}, [source, logout]);
|
|
60
|
+
}, [source, logout, authStrategy]);
|
|
57
61
|
|
|
58
62
|
const [step, setStep] = useState<"login" | "permissions" | null>(source === "requestPermissions" ? null : "login");
|
|
59
63
|
const [sessionKeyAdded, setSessionKeyAdded] = useState(source === "requestPermissions" ? true : false);
|
|
@@ -292,6 +296,8 @@ export function SignInWithB3Flow({
|
|
|
292
296
|
</div>
|
|
293
297
|
</LoginStepContainer>
|
|
294
298
|
);
|
|
299
|
+
} else if (authStrategy === "better-auth") {
|
|
300
|
+
content = <LoginStepBetterAuth onSuccess={() => handleLoginSuccess({} as Account)} onError={onError} />;
|
|
295
301
|
} else {
|
|
296
302
|
// Custom strategy
|
|
297
303
|
if (strategies?.[0] === "privy") {
|