@b3dotfun/sdk 0.1.69-alpha.17 → 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/utils/chain.js +1 -1
- 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/index.d.ts +3 -0
- package/dist/cjs/global-account/react/components/index.js +7 -3
- 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/esm/anyspend/utils/chain.js +1 -1
- 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/index.d.ts +3 -0
- package/dist/esm/global-account/react/components/index.js +2 -0
- 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/styles/index.css +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/index.d.ts +3 -0
- 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/package.json +2 -1
- package/src/anyspend/utils/chain.ts +1 -2
- 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
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { Button, Input, LoginStepContainer, useB3Config } from "../../../../../global-account/react/index.js";
|
|
3
|
+
import { debugB3React } from "../../../../../shared/utils/debug.js";
|
|
4
|
+
import { useState } from "react";
|
|
5
|
+
import { useBetterAuth } from "../../../hooks/useBetterAuth.js";
|
|
6
|
+
import { AuthButton } from "../components/AuthButton.js";
|
|
7
|
+
const debug = debugB3React("LoginStepBetterAuth");
|
|
8
|
+
const EMAIL_REGEX = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
|
|
9
|
+
const SOCIAL_PROVIDERS = [
|
|
10
|
+
{ id: "google", label: "Google" },
|
|
11
|
+
{ id: "github", label: "GitHub" },
|
|
12
|
+
{ id: "discord", label: "Discord" },
|
|
13
|
+
{ id: "microsoft", label: "Microsoft" },
|
|
14
|
+
{ id: "slack", label: "Slack" },
|
|
15
|
+
];
|
|
16
|
+
export function LoginStepBetterAuth({ onSuccess, onError }) {
|
|
17
|
+
const { partnerId } = useB3Config();
|
|
18
|
+
const { signInWithEmail, signUpWithEmail, signInWithSocial, requestPasswordReset } = useBetterAuth();
|
|
19
|
+
const [mode, setMode] = useState("sign-in");
|
|
20
|
+
const [showEmailForm, setShowEmailForm] = useState(false);
|
|
21
|
+
const [email, setEmail] = useState("");
|
|
22
|
+
const [password, setPassword] = useState("");
|
|
23
|
+
const [name, setName] = useState("");
|
|
24
|
+
const [isLoading, setIsLoading] = useState(false);
|
|
25
|
+
const [error, setError] = useState(null);
|
|
26
|
+
const [resetEmailSent, setResetEmailSent] = useState(false);
|
|
27
|
+
const handleEmailSubmit = async () => {
|
|
28
|
+
const normalizedEmail = email.trim().toLowerCase();
|
|
29
|
+
if (!EMAIL_REGEX.test(normalizedEmail)) {
|
|
30
|
+
setError("Please enter a valid email address");
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
if (!password) {
|
|
34
|
+
setError("Please enter a password");
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
if (mode === "sign-up" && !name.trim()) {
|
|
38
|
+
setError("Please enter your name");
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
try {
|
|
42
|
+
setIsLoading(true);
|
|
43
|
+
setError(null);
|
|
44
|
+
if (mode === "sign-up") {
|
|
45
|
+
debug("Signing up", { email: normalizedEmail, name: name.trim() });
|
|
46
|
+
await signUpWithEmail(normalizedEmail, password, name.trim());
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
debug("Signing in", { email: normalizedEmail });
|
|
50
|
+
await signInWithEmail(normalizedEmail, password);
|
|
51
|
+
}
|
|
52
|
+
debug("Auth successful");
|
|
53
|
+
onSuccess?.();
|
|
54
|
+
}
|
|
55
|
+
catch (err) {
|
|
56
|
+
const message = err instanceof Error ? err.message : "Authentication failed";
|
|
57
|
+
setError(message);
|
|
58
|
+
debug("Auth failed", err);
|
|
59
|
+
await onError?.(err);
|
|
60
|
+
}
|
|
61
|
+
finally {
|
|
62
|
+
setPassword("");
|
|
63
|
+
setIsLoading(false);
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
const handleForgotPassword = async () => {
|
|
67
|
+
const normalizedEmail = email.trim().toLowerCase();
|
|
68
|
+
if (!EMAIL_REGEX.test(normalizedEmail)) {
|
|
69
|
+
setError("Please enter a valid email address");
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
try {
|
|
73
|
+
setIsLoading(true);
|
|
74
|
+
setError(null);
|
|
75
|
+
await requestPasswordReset(normalizedEmail);
|
|
76
|
+
setResetEmailSent(true);
|
|
77
|
+
}
|
|
78
|
+
catch (err) {
|
|
79
|
+
const message = err instanceof Error ? err.message : "Failed to send reset email";
|
|
80
|
+
setError(message);
|
|
81
|
+
}
|
|
82
|
+
finally {
|
|
83
|
+
setIsLoading(false);
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
const handleSocialSignIn = async (provider) => {
|
|
87
|
+
try {
|
|
88
|
+
setIsLoading(true);
|
|
89
|
+
setError(null);
|
|
90
|
+
await signInWithSocial(provider);
|
|
91
|
+
}
|
|
92
|
+
catch (err) {
|
|
93
|
+
const message = err instanceof Error ? err.message : `${provider} sign in failed`;
|
|
94
|
+
setError(message);
|
|
95
|
+
await onError?.(err);
|
|
96
|
+
setIsLoading(false);
|
|
97
|
+
}
|
|
98
|
+
};
|
|
99
|
+
return (_jsx(LoginStepContainer, { partnerId: partnerId, children: mode === "forgot-password" ? (_jsxs("div", { className: "mb-6 w-full space-y-3 px-3", children: [_jsx("p", { className: "text-center text-sm font-medium text-gray-900 dark:text-gray-100", children: "Reset password" }), _jsx("p", { className: "text-center text-xs text-gray-500", children: "Enter your email and we'll send you a reset link" }), resetEmailSent ? (_jsx("div", { className: "space-y-3 py-4 text-center", children: _jsx("p", { className: "text-sm text-green-600", children: "Check your email for a reset link." }) })) : (_jsxs(_Fragment, { children: [_jsx(Input, { type: "email", placeholder: "you@example.com", value: email, onChange: event => setEmail(event.target.value), disabled: isLoading, onKeyDown: event => {
|
|
100
|
+
if (event.key === "Enter")
|
|
101
|
+
handleForgotPassword();
|
|
102
|
+
} }), error && _jsx("p", { className: "text-sm text-red-500", children: error }), _jsx(Button, { onClick: handleForgotPassword, disabled: isLoading, className: "w-full", children: isLoading ? "Sending..." : "Send reset link" })] })), _jsx("button", { onClick: () => {
|
|
103
|
+
setMode("sign-in");
|
|
104
|
+
setShowEmailForm(true);
|
|
105
|
+
setError(null);
|
|
106
|
+
setResetEmailSent(false);
|
|
107
|
+
}, className: "w-full text-center text-sm text-gray-500 hover:text-gray-700", children: "Back to sign in" })] })) : showEmailForm ? (_jsxs("div", { className: "mb-6 w-full space-y-3 px-3", children: [_jsx("p", { className: "text-center text-sm font-medium text-gray-900 dark:text-gray-100", children: mode === "sign-in" ? "Sign in with email" : "Create an account" }), mode === "sign-up" && (_jsx(Input, { type: "text", placeholder: "Your name", value: name, onChange: event => setName(event.target.value), disabled: isLoading })), _jsx(Input, { type: "email", placeholder: "you@example.com", value: email, onChange: event => setEmail(event.target.value), disabled: isLoading }), _jsx(Input, { type: "password", placeholder: "Password", value: password, onChange: event => setPassword(event.target.value), disabled: isLoading, onKeyDown: event => {
|
|
108
|
+
if (event.key === "Enter")
|
|
109
|
+
handleEmailSubmit();
|
|
110
|
+
} }), error && _jsx("p", { className: "text-sm text-red-500", children: error }), _jsx(Button, { onClick: handleEmailSubmit, disabled: isLoading, className: "w-full", children: isLoading ? "Loading..." : mode === "sign-in" ? "Sign in" : "Sign up" }), mode === "sign-in" && (_jsx("button", { onClick: () => {
|
|
111
|
+
setMode("forgot-password");
|
|
112
|
+
setError(null);
|
|
113
|
+
}, disabled: isLoading, className: "w-full text-center text-xs text-gray-500 hover:text-gray-700", children: "Forgot password?" })), _jsx("button", { onClick: () => {
|
|
114
|
+
setMode(mode === "sign-in" ? "sign-up" : "sign-in");
|
|
115
|
+
setError(null);
|
|
116
|
+
}, disabled: isLoading, className: "w-full text-center text-sm text-gray-500 hover:text-gray-700", children: mode === "sign-in" ? "Don't have an account? Sign up" : "Already have an account? Sign in" }), _jsx(Button, { variant: "outline", onClick: () => {
|
|
117
|
+
setShowEmailForm(false);
|
|
118
|
+
setError(null);
|
|
119
|
+
}, disabled: isLoading, className: "w-full", children: "Back" })] })) : (_jsxs("div", { className: "mb-6 w-full space-y-4 px-3", children: [_jsx("div", { className: "grid w-full grid-cols-3 gap-4", children: SOCIAL_PROVIDERS.map(provider => (_jsx(AuthButton, { strategy: provider.id, onClick: () => handleSocialSignIn(provider.id), isLoading: isLoading }, provider.id))) }), _jsxs("div", { className: "flex items-center gap-3", children: [_jsx("div", { className: "h-px flex-1 bg-gray-200" }), _jsx("span", { className: "text-xs text-gray-400", children: "or" }), _jsx("div", { className: "h-px flex-1 bg-gray-200" })] }), _jsx(AuthButton, { strategy: "email", onClick: () => setShowEmailForm(true), isLoading: isLoading }), error && _jsx("p", { className: "text-center text-sm text-red-500", children: error })] })) }));
|
|
120
|
+
}
|
|
@@ -43,11 +43,13 @@ export function getConnectOptionsFromStrategy(strategy) {
|
|
|
43
43
|
}
|
|
44
44
|
export const strategyIcons = {
|
|
45
45
|
google: "https://cdn.b3.fun/google.svg",
|
|
46
|
+
github: "https://cdn.jsdelivr.net/gh/devicons/devicon/icons/github/github-original.svg",
|
|
46
47
|
x: "https://cdn.b3.fun/x.svg?1",
|
|
47
48
|
discord: "https://cdn.b3.fun/discord.svg",
|
|
48
49
|
apple: "https://cdn.b3.fun/apple.svg",
|
|
49
50
|
guest: "https://cdn.b3.fun/incognito.svg",
|
|
50
|
-
|
|
51
|
+
microsoft: "https://upload.wikimedia.org/wikipedia/commons/4/44/Microsoft_logo.svg",
|
|
52
|
+
slack: "https://upload.wikimedia.org/wikipedia/commons/d/d5/Slack_icon_2019.svg",
|
|
51
53
|
};
|
|
52
54
|
export const strategyLabels = {
|
|
53
55
|
google: "Google",
|
|
@@ -57,6 +59,8 @@ export const strategyLabels = {
|
|
|
57
59
|
guest: "Guest",
|
|
58
60
|
github: "GitHub",
|
|
59
61
|
email: "Email",
|
|
62
|
+
microsoft: "Microsoft",
|
|
63
|
+
slack: "Slack",
|
|
60
64
|
};
|
|
61
65
|
// Test it
|
|
62
66
|
// console.log(getConnectOptionsFromStrategy("io.metamask"));
|
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
export { B3DynamicModal } from "./B3DynamicModal";
|
|
2
2
|
export { B3Provider } from "./B3Provider/B3Provider";
|
|
3
|
+
export type { AuthStrategy } from "./B3Provider/B3ConfigProvider";
|
|
3
4
|
export { RelayKitProviderWrapper } from "./B3Provider/RelayKitProviderWrapper";
|
|
4
5
|
export { useB3 } from "./B3Provider/useB3";
|
|
5
6
|
export { useB3Account } from "./B3Provider/useB3Account";
|
|
6
7
|
export { useB3Config } from "./B3Provider/useB3Config";
|
|
7
8
|
export { StyleRoot } from "./StyleRoot";
|
|
9
|
+
export { BetterAuthResetPassword, type BetterAuthResetPasswordProps } from "./SignInWithB3/BetterAuthResetPassword";
|
|
10
|
+
export { BetterAuthSignIn, type BetterAuthSignInProps } from "./SignInWithB3/BetterAuthSignIn";
|
|
8
11
|
export { AuthButton } from "./SignInWithB3/components/AuthButton";
|
|
9
12
|
export { PermissionItem } from "./SignInWithB3/components/PermissionItem";
|
|
10
13
|
export { WalletRow } from "./SignInWithB3/components/WalletRow";
|
|
@@ -8,6 +8,8 @@ export { useB3Account } from "./B3Provider/useB3Account.js";
|
|
|
8
8
|
export { useB3Config } from "./B3Provider/useB3Config.js";
|
|
9
9
|
export { StyleRoot } from "./StyleRoot.js";
|
|
10
10
|
// SignInWithB3 Components
|
|
11
|
+
export { BetterAuthResetPassword } from "./SignInWithB3/BetterAuthResetPassword.js";
|
|
12
|
+
export { BetterAuthSignIn } from "./SignInWithB3/BetterAuthSignIn.js";
|
|
11
13
|
export { AuthButton } from "./SignInWithB3/components/AuthButton.js";
|
|
12
14
|
export { PermissionItem } from "./SignInWithB3/components/PermissionItem.js";
|
|
13
15
|
export { WalletRow } from "./SignInWithB3/components/WalletRow.js";
|
|
@@ -5,6 +5,7 @@ export { useAddTWSessionKey } from "./useAddTWSessionKey";
|
|
|
5
5
|
export { useAnalytics } from "./useAnalytics";
|
|
6
6
|
export { useAuth } from "./useAuth";
|
|
7
7
|
export { useAuthentication } from "./useAuthentication";
|
|
8
|
+
export { useBetterAuth } from "./useBetterAuth";
|
|
8
9
|
export { useB3BalanceFromAddresses } from "./useB3BalanceFromAddresses";
|
|
9
10
|
export { useB3EnsName } from "./useB3EnsName";
|
|
10
11
|
export { useChainSwitchWithAction } from "./useChainSwitchWithAction";
|
|
@@ -5,6 +5,7 @@ export { useAddTWSessionKey } from "./useAddTWSessionKey.js";
|
|
|
5
5
|
export { useAnalytics } from "./useAnalytics.js";
|
|
6
6
|
export { useAuth } from "./useAuth.js";
|
|
7
7
|
export { useAuthentication } from "./useAuthentication.js";
|
|
8
|
+
export { useBetterAuth } from "./useBetterAuth.js";
|
|
8
9
|
export { useB3BalanceFromAddresses } from "./useB3BalanceFromAddresses.js";
|
|
9
10
|
export { useB3EnsName } from "./useB3EnsName.js";
|
|
10
11
|
export { useChainSwitchWithAction } from "./useChainSwitchWithAction.js";
|