@b3dotfun/sdk 0.1.70-alpha.3 → 0.1.70-alpha.5
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/app.shared.d.ts +8 -0
- package/dist/cjs/app.shared.js +19 -0
- package/dist/cjs/global-account/better-auth-client.d.ts +8 -0
- package/dist/cjs/global-account/better-auth-client.js +26 -3
- package/dist/cjs/global-account/client-manager.d.ts +2 -0
- package/dist/cjs/global-account/client-manager.js +19 -4
- package/dist/cjs/global-account/react/components/B3Provider/B3Provider.d.ts +10 -1
- package/dist/cjs/global-account/react/components/B3Provider/B3Provider.js +15 -1
- package/dist/cjs/global-account/react/components/B3Provider/BetterAuthProvider.js +45 -4
- package/dist/cjs/global-account/react/components/SignInWithB3/SignInWithB3Flow.js +1 -5
- package/dist/cjs/global-account/react/components/SignInWithB3/utils/signInUtils.d.ts +3 -2
- package/dist/cjs/global-account/react/components/SignInWithB3/utils/signInUtils.js +1 -3
- package/dist/cjs/global-account/react/components/index.d.ts +0 -1
- package/dist/cjs/global-account/react/components/index.js +3 -5
- package/dist/cjs/global-account/react/hooks/index.d.ts +0 -1
- package/dist/cjs/global-account/react/hooks/index.js +2 -4
- package/dist/cjs/global-account/react/hooks/useBetterAuth.js +7 -7
- package/dist/cjs/global-account/types/b3-api.types.d.ts +5 -0
- package/dist/esm/app.shared.d.ts +8 -0
- package/dist/esm/app.shared.js +17 -0
- package/dist/esm/global-account/better-auth-client.d.ts +8 -0
- package/dist/esm/global-account/better-auth-client.js +25 -4
- package/dist/esm/global-account/client-manager.d.ts +2 -0
- package/dist/esm/global-account/client-manager.js +19 -5
- package/dist/esm/global-account/react/components/B3Provider/B3Provider.d.ts +10 -1
- package/dist/esm/global-account/react/components/B3Provider/B3Provider.js +16 -2
- package/dist/esm/global-account/react/components/B3Provider/BetterAuthProvider.js +46 -5
- package/dist/esm/global-account/react/components/SignInWithB3/SignInWithB3Flow.js +1 -5
- package/dist/esm/global-account/react/components/SignInWithB3/utils/signInUtils.d.ts +3 -2
- package/dist/esm/global-account/react/components/SignInWithB3/utils/signInUtils.js +1 -3
- package/dist/esm/global-account/react/components/index.d.ts +0 -1
- package/dist/esm/global-account/react/components/index.js +0 -1
- package/dist/esm/global-account/react/hooks/index.d.ts +0 -1
- package/dist/esm/global-account/react/hooks/index.js +0 -1
- package/dist/esm/global-account/react/hooks/useBetterAuth.js +8 -8
- package/dist/esm/global-account/types/b3-api.types.d.ts +5 -0
- package/dist/types/app.shared.d.ts +8 -0
- package/dist/types/global-account/better-auth-client.d.ts +8 -0
- package/dist/types/global-account/client-manager.d.ts +2 -0
- package/dist/types/global-account/react/components/B3Provider/B3Provider.d.ts +10 -1
- package/dist/types/global-account/react/components/SignInWithB3/utils/signInUtils.d.ts +3 -2
- package/dist/types/global-account/react/components/index.d.ts +0 -1
- package/dist/types/global-account/react/hooks/index.d.ts +0 -1
- package/dist/types/global-account/types/b3-api.types.d.ts +5 -0
- package/package.json +2 -2
- package/src/app.shared.ts +20 -0
- package/src/global-account/better-auth-client.ts +28 -4
- package/src/global-account/client-manager.ts +20 -5
- package/src/global-account/react/components/B3Provider/B3Provider.tsx +26 -1
- package/src/global-account/react/components/B3Provider/BetterAuthProvider.tsx +51 -5
- package/src/global-account/react/components/SignInWithB3/SignInWithB3Flow.tsx +1 -4
- package/src/global-account/react/components/SignInWithB3/utils/signInUtils.ts +2 -4
- package/src/global-account/react/components/index.ts +0 -1
- package/src/global-account/react/hooks/index.ts +0 -1
- package/src/global-account/react/hooks/useBetterAuth.ts +8 -8
- package/src/global-account/types/b3-api.types.ts +5 -1
- package/dist/cjs/global-account/react/components/SignInWithB3/SignInWithB3Privy.d.ts +0 -10
- package/dist/cjs/global-account/react/components/SignInWithB3/SignInWithB3Privy.js +0 -46
- package/dist/cjs/global-account/react/hooks/useHandleConnectWithPrivy.d.ts +0 -11
- package/dist/cjs/global-account/react/hooks/useHandleConnectWithPrivy.js +0 -70
- package/dist/esm/global-account/react/components/SignInWithB3/SignInWithB3Privy.d.ts +0 -10
- package/dist/esm/global-account/react/components/SignInWithB3/SignInWithB3Privy.js +0 -43
- package/dist/esm/global-account/react/hooks/useHandleConnectWithPrivy.d.ts +0 -11
- package/dist/esm/global-account/react/hooks/useHandleConnectWithPrivy.js +0 -67
- package/dist/types/global-account/react/components/SignInWithB3/SignInWithB3Privy.d.ts +0 -10
- package/dist/types/global-account/react/hooks/useHandleConnectWithPrivy.d.ts +0 -11
- package/src/global-account/react/components/SignInWithB3/SignInWithB3Privy.tsx +0 -63
- package/src/global-account/react/hooks/useHandleConnectWithPrivy.tsx +0 -79
|
@@ -2,7 +2,7 @@ import { ClientApplication, createClient } from "@b3dotfun/b3-api";
|
|
|
2
2
|
import rest from "@feathersjs/rest-client";
|
|
3
3
|
import socketio from "@feathersjs/socketio-client";
|
|
4
4
|
import io from "socket.io-client";
|
|
5
|
-
import { authenticate as authenticateB3,
|
|
5
|
+
import { authenticate as authenticateB3, getB3ApiUrl, clientOptions } from "../app.shared";
|
|
6
6
|
|
|
7
7
|
export type ClientType = "socket" | "rest";
|
|
8
8
|
|
|
@@ -13,17 +13,21 @@ let currentClient: ClientApplication | null = null;
|
|
|
13
13
|
// Socket client instance
|
|
14
14
|
let socketClient: ClientApplication | null = null;
|
|
15
15
|
let socketInstance: any = null;
|
|
16
|
+
let socketClientUrl: string | null = null;
|
|
16
17
|
|
|
17
18
|
// REST client instance
|
|
18
19
|
let restClient: ClientApplication | null = null;
|
|
20
|
+
let restClientUrl: string | null = null;
|
|
19
21
|
|
|
20
22
|
/**
|
|
21
23
|
* Creates a socket client
|
|
22
24
|
*/
|
|
23
25
|
function createSocketClient(): ClientApplication {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
+
const url = getB3ApiUrl();
|
|
27
|
+
if (!socketClient || socketClientUrl !== url) {
|
|
28
|
+
socketInstance = io(url, { transports: ["websocket"] });
|
|
26
29
|
socketClient = createClient(socketio(socketInstance), clientOptions);
|
|
30
|
+
socketClientUrl = url;
|
|
27
31
|
}
|
|
28
32
|
return socketClient;
|
|
29
33
|
}
|
|
@@ -40,13 +44,24 @@ function resolveFetch(): typeof fetch {
|
|
|
40
44
|
}
|
|
41
45
|
|
|
42
46
|
function createRestClient(): ClientApplication {
|
|
43
|
-
|
|
44
|
-
|
|
47
|
+
const url = getB3ApiUrl();
|
|
48
|
+
if (!restClient || restClientUrl !== url) {
|
|
49
|
+
const connection = rest(url).fetch(resolveFetch());
|
|
45
50
|
restClient = createClient(connection, clientOptions);
|
|
51
|
+
restClientUrl = url;
|
|
46
52
|
}
|
|
47
53
|
return restClient;
|
|
48
54
|
}
|
|
49
55
|
|
|
56
|
+
/** Reset all cached clients (called when API URL changes). */
|
|
57
|
+
export function resetClients(): void {
|
|
58
|
+
socketClient = null;
|
|
59
|
+
socketClientUrl = null;
|
|
60
|
+
restClient = null;
|
|
61
|
+
restClientUrl = null;
|
|
62
|
+
currentClient = null;
|
|
63
|
+
}
|
|
64
|
+
|
|
50
65
|
/**
|
|
51
66
|
* Sets the active client type and creates the appropriate client
|
|
52
67
|
*
|
|
@@ -11,7 +11,9 @@ import { QueryClient } from "@tanstack/react-query";
|
|
|
11
11
|
import { useEffect, useMemo } from "react";
|
|
12
12
|
import { Account, EIP1193, Wallet } from "thirdweb/wallets";
|
|
13
13
|
import { CreateConnectorFn } from "wagmi";
|
|
14
|
-
import { ClientType, setClientType } from "../../../client-manager";
|
|
14
|
+
import { ClientType, resetClients, setClientType } from "../../../client-manager";
|
|
15
|
+
import { setB3ApiUrl } from "../../../../app.shared";
|
|
16
|
+
import { resetBetterAuthClient } from "../../../better-auth-client";
|
|
15
17
|
import { StyleRoot } from "../StyleRoot";
|
|
16
18
|
import { setToastContext, ToastProvider, useToastContext } from "../Toast/index";
|
|
17
19
|
import AuthenticationProvider from "./AuthenticationProvider";
|
|
@@ -45,6 +47,7 @@ export function B3Provider({
|
|
|
45
47
|
disableBSMNTAuthentication = false,
|
|
46
48
|
queryClient,
|
|
47
49
|
authStrategy = "thirdweb",
|
|
50
|
+
apiUrl,
|
|
48
51
|
}: {
|
|
49
52
|
theme: "light" | "dark";
|
|
50
53
|
children: React.ReactNode;
|
|
@@ -74,7 +77,29 @@ export function B3Provider({
|
|
|
74
77
|
queryClient?: QueryClient;
|
|
75
78
|
/** Auth strategy: "thirdweb" (default, ecosystem wallet) or "better-auth" (email/password via Better Auth) */
|
|
76
79
|
authStrategy?: AuthStrategy;
|
|
80
|
+
/**
|
|
81
|
+
* Override the B3 API URL. When provided, all SDK requests (auth, Feathers,
|
|
82
|
+
* BetterAuth) will use this URL instead of the `NEXT_PUBLIC_B3_API` env var.
|
|
83
|
+
*
|
|
84
|
+
* Useful for local development: pass `http://localhost:3031` to route
|
|
85
|
+
* OAuth callbacks and session checks through your local B3 API.
|
|
86
|
+
* If omitted, defaults to `NEXT_PUBLIC_B3_API` or `https://api.b3.fun`.
|
|
87
|
+
*/
|
|
88
|
+
apiUrl?: string;
|
|
77
89
|
}) {
|
|
90
|
+
// Override the B3 API URL when the `apiUrl` prop is provided.
|
|
91
|
+
// Must run before client initialization and auth providers mount.
|
|
92
|
+
useEffect(() => {
|
|
93
|
+
setB3ApiUrl(apiUrl ?? null);
|
|
94
|
+
if (apiUrl) {
|
|
95
|
+
resetBetterAuthClient();
|
|
96
|
+
resetClients();
|
|
97
|
+
}
|
|
98
|
+
return () => {
|
|
99
|
+
setB3ApiUrl(null);
|
|
100
|
+
};
|
|
101
|
+
}, [apiUrl]);
|
|
102
|
+
|
|
78
103
|
// Initialize Google Analytics on mount
|
|
79
104
|
useEffect(() => {
|
|
80
105
|
loadGA4Script();
|
|
@@ -4,7 +4,7 @@ import { B3_AUTH_COOKIE_NAME } from "@b3dotfun/sdk/shared/constants";
|
|
|
4
4
|
import { debugB3React } from "@b3dotfun/sdk/shared/utils/debug";
|
|
5
5
|
import Cookies from "js-cookie";
|
|
6
6
|
import { useEffect, useRef } from "react";
|
|
7
|
-
import {
|
|
7
|
+
import { getBetterAuthClient } from "../../../better-auth-client";
|
|
8
8
|
import { useUserQuery } from "../../hooks/useUserQuery";
|
|
9
9
|
|
|
10
10
|
const debug = debugB3React("BetterAuthProvider");
|
|
@@ -43,7 +43,7 @@ const BetterAuthProvider = ({ partnerId }: { partnerId: string }) => {
|
|
|
43
43
|
(app as any).logout = async () => {
|
|
44
44
|
debug("Patched logout: clearing Better Auth session");
|
|
45
45
|
try {
|
|
46
|
-
await
|
|
46
|
+
await getBetterAuthClient().signOut();
|
|
47
47
|
} catch {
|
|
48
48
|
debug("Better Auth signOut failed (non-critical)");
|
|
49
49
|
}
|
|
@@ -79,9 +79,55 @@ const BetterAuthProvider = ({ partnerId }: { partnerId: string }) => {
|
|
|
79
79
|
debug("No existing Feathers JWT");
|
|
80
80
|
}
|
|
81
81
|
|
|
82
|
-
// 2. Check for
|
|
82
|
+
// 2. Check for _ba_token in URL (OAuth callback with third-party cookie bypass).
|
|
83
|
+
// When the API and frontend are on different domains, browsers with third-party
|
|
84
|
+
// cookie blocking (Firefox TCP, Safari ITP, Chrome Privacy Sandbox) prevent the
|
|
85
|
+
// better-auth.session_token cookie from being sent on cross-origin requests.
|
|
86
|
+
// The B3 API injects the session token into the redirect URL as _ba_token,
|
|
87
|
+
// allowing direct exchange without relying on cookies.
|
|
88
|
+
const params = new URLSearchParams(window.location.search);
|
|
89
|
+
const baToken = params.get("_ba_token");
|
|
90
|
+
if (baToken) {
|
|
91
|
+
debug("Found _ba_token in URL, exchanging for Feathers JWT");
|
|
92
|
+
|
|
93
|
+
// Clean the token from the URL immediately (security)
|
|
94
|
+
params.delete("_ba_token");
|
|
95
|
+
const cleanSearch = params.toString();
|
|
96
|
+
const cleanUrl = window.location.pathname + (cleanSearch ? `?${cleanSearch}` : "") + window.location.hash;
|
|
97
|
+
window.history.replaceState({}, "", cleanUrl);
|
|
98
|
+
|
|
99
|
+
try {
|
|
100
|
+
const response = await app.authenticate({
|
|
101
|
+
strategy: "better-auth",
|
|
102
|
+
accessToken: baToken,
|
|
103
|
+
partnerId,
|
|
104
|
+
} as any);
|
|
105
|
+
|
|
106
|
+
if (response.accessToken) {
|
|
107
|
+
Cookies.set(B3_AUTH_COOKIE_NAME, response.accessToken, {
|
|
108
|
+
secure: true,
|
|
109
|
+
sameSite: "Lax",
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
if (response.user) {
|
|
114
|
+
setUser(response.user);
|
|
115
|
+
setIsAuthenticated(true);
|
|
116
|
+
setIsConnected(true);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
debug("_ba_token exchanged for Feathers JWT", { userId: response.user?.userId });
|
|
120
|
+
setIsAuthenticating(false);
|
|
121
|
+
return;
|
|
122
|
+
} catch (err) {
|
|
123
|
+
debug("_ba_token exchange failed", err);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
// 3. Check for a Better Auth session via cookie (works when API and frontend
|
|
128
|
+
// share a domain or when cookies aren't partitioned)
|
|
83
129
|
try {
|
|
84
|
-
const session = await
|
|
130
|
+
const session = await getBetterAuthClient().getSession();
|
|
85
131
|
if (session.data?.session?.token) {
|
|
86
132
|
debug("Better Auth session found, exchanging for Feathers JWT", {
|
|
87
133
|
betterAuthUserId: session.data.user?.id,
|
|
@@ -114,7 +160,7 @@ const BetterAuthProvider = ({ partnerId }: { partnerId: string }) => {
|
|
|
114
160
|
debug("No Better Auth session to restore");
|
|
115
161
|
}
|
|
116
162
|
|
|
117
|
-
//
|
|
163
|
+
// 4. Nothing found — show login UI
|
|
118
164
|
setIsAuthenticating(false);
|
|
119
165
|
};
|
|
120
166
|
|
|
@@ -12,7 +12,6 @@ import { debugB3React } from "@b3dotfun/sdk/shared/utils/debug";
|
|
|
12
12
|
import { useCallback, useEffect, useRef, useState } from "react";
|
|
13
13
|
import { useActiveAccount } from "thirdweb/react";
|
|
14
14
|
import { Account } from "thirdweb/wallets";
|
|
15
|
-
import { SignInWithB3Privy } from "./SignInWithB3Privy";
|
|
16
15
|
import { LoginStep, LoginStepContainer } from "./steps/LoginStep";
|
|
17
16
|
import { LoginStepCustom } from "./steps/LoginStepCustom";
|
|
18
17
|
|
|
@@ -310,9 +309,7 @@ export function SignInWithB3Flow({
|
|
|
310
309
|
);
|
|
311
310
|
} else {
|
|
312
311
|
// Custom strategy
|
|
313
|
-
if (strategies
|
|
314
|
-
content = <SignInWithB3Privy onSuccess={handleLoginSuccess} chain={chain} />;
|
|
315
|
-
} else if (strategies) {
|
|
312
|
+
if (strategies) {
|
|
316
313
|
// Strategies are explicitly provided
|
|
317
314
|
content = (
|
|
318
315
|
<LoginStepCustom
|
|
@@ -3,12 +3,11 @@ import { createWallet, SingleStepAuthArgsType, Wallet } from "thirdweb/wallets";
|
|
|
3
3
|
|
|
4
4
|
type WalletType = Wallet["id"];
|
|
5
5
|
type StrategyType = SingleStepAuthArgsType["strategy"];
|
|
6
|
-
|
|
6
|
+
const customStrategies = ["basement"] as const;
|
|
7
|
+
type CustomStrategyType = (typeof customStrategies)[number];
|
|
7
8
|
|
|
8
9
|
type AllowedStrategies = StrategyType | WalletType | CustomStrategyType | "email";
|
|
9
10
|
type NonWalletStrategyType = Exclude<AllowedStrategies, WalletType>;
|
|
10
|
-
const customStrategies = ["basement", "privy"] as const;
|
|
11
|
-
// type CustomStrategy = (typeof customStrategies)[number];
|
|
12
11
|
|
|
13
12
|
export const allowedStrategies = [
|
|
14
13
|
// Auth strategies
|
|
@@ -26,7 +25,6 @@ export const allowedStrategies = [
|
|
|
26
25
|
"com.coinbase.wallet",
|
|
27
26
|
|
|
28
27
|
// Custom strategies
|
|
29
|
-
// TODO: Audit we don't use "privy" directly anymore
|
|
30
28
|
...customStrategies,
|
|
31
29
|
] as const;
|
|
32
30
|
|
|
@@ -22,7 +22,6 @@ export { PermissionItem } from "./SignInWithB3/components/PermissionItem";
|
|
|
22
22
|
export { WalletRow } from "./SignInWithB3/components/WalletRow";
|
|
23
23
|
export { SignInWithB3 } from "./SignInWithB3/SignInWithB3";
|
|
24
24
|
export { SignInWithB3Flow } from "./SignInWithB3/SignInWithB3Flow";
|
|
25
|
-
export { SignInWithB3Privy } from "./SignInWithB3/SignInWithB3Privy";
|
|
26
25
|
export { LoginStepContainer } from "./SignInWithB3/steps/LoginStep";
|
|
27
26
|
export { getConnectOptionsFromStrategy, isWalletType, type AllowedStrategy } from "./SignInWithB3/utils/signInUtils";
|
|
28
27
|
|
|
@@ -17,7 +17,6 @@ export { useFirstEOA } from "./useFirstEOA";
|
|
|
17
17
|
export { useGetAllTWSigners, type TWSignerWithMetadata } from "./useGetAllTWSigners";
|
|
18
18
|
export { useGetGeo } from "./useGetGeo";
|
|
19
19
|
export { useGlobalAccount } from "./useGlobalAccount";
|
|
20
|
-
export { useHandleConnectWithPrivy } from "./useHandleConnectWithPrivy";
|
|
21
20
|
export { useHasMounted } from "./useHasMounted";
|
|
22
21
|
export { useIsMobile } from "./useIsMobile";
|
|
23
22
|
export { useIsomorphicLayoutEffect } from "./useIsomorphicLayoutEffect";
|
|
@@ -2,7 +2,7 @@ import app from "@b3dotfun/sdk/global-account/app";
|
|
|
2
2
|
import { useAuthStore, useB3Config } from "@b3dotfun/sdk/global-account/react";
|
|
3
3
|
import { debugB3React } from "@b3dotfun/sdk/shared/utils/debug";
|
|
4
4
|
import { useCallback } from "react";
|
|
5
|
-
import {
|
|
5
|
+
import { getBetterAuthClient } from "../../better-auth-client";
|
|
6
6
|
import { useUserQuery } from "./useUserQuery";
|
|
7
7
|
|
|
8
8
|
const debug = debugB3React("useBetterAuth");
|
|
@@ -65,7 +65,7 @@ export function useBetterAuth() {
|
|
|
65
65
|
setIsAuthenticating(true);
|
|
66
66
|
|
|
67
67
|
try {
|
|
68
|
-
const result = await
|
|
68
|
+
const result = await getBetterAuthClient().signIn.email({ email, password });
|
|
69
69
|
|
|
70
70
|
if (result.error) {
|
|
71
71
|
throw new Error(result.error.message || "Sign in failed");
|
|
@@ -93,7 +93,7 @@ export function useBetterAuth() {
|
|
|
93
93
|
setIsAuthenticating(true);
|
|
94
94
|
|
|
95
95
|
try {
|
|
96
|
-
const result = await
|
|
96
|
+
const result = await getBetterAuthClient().signUp.email({ email, password, name });
|
|
97
97
|
|
|
98
98
|
if (result.error) {
|
|
99
99
|
throw new Error(result.error.message || "Sign up failed");
|
|
@@ -104,7 +104,7 @@ export function useBetterAuth() {
|
|
|
104
104
|
// requireEmailVerification is enabled — send verification email with
|
|
105
105
|
// a callbackURL Better Auth redirects to after server-side verify.
|
|
106
106
|
// Pass verifyCallbackURL to land on a dedicated confirmation page.
|
|
107
|
-
await
|
|
107
|
+
await getBetterAuthClient().sendVerificationEmail({
|
|
108
108
|
email,
|
|
109
109
|
callbackURL: verifyCallbackURL || `${window.location.origin}?authStrategy=better-auth`,
|
|
110
110
|
});
|
|
@@ -128,7 +128,7 @@ export function useBetterAuth() {
|
|
|
128
128
|
setIsAuthenticating(true);
|
|
129
129
|
|
|
130
130
|
try {
|
|
131
|
-
const result = await
|
|
131
|
+
const result = await getBetterAuthClient().signIn.social({
|
|
132
132
|
provider,
|
|
133
133
|
callbackURL: window.location.href,
|
|
134
134
|
});
|
|
@@ -151,7 +151,7 @@ export function useBetterAuth() {
|
|
|
151
151
|
const requestPasswordReset = useCallback(async (email: string, redirectTo?: string) => {
|
|
152
152
|
debug("Requesting password reset", { email });
|
|
153
153
|
|
|
154
|
-
const result = await
|
|
154
|
+
const result = await getBetterAuthClient().requestPasswordReset({
|
|
155
155
|
email,
|
|
156
156
|
redirectTo,
|
|
157
157
|
});
|
|
@@ -167,7 +167,7 @@ export function useBetterAuth() {
|
|
|
167
167
|
const resetPassword = useCallback(async (newPassword: string, token: string) => {
|
|
168
168
|
debug("Resetting password");
|
|
169
169
|
|
|
170
|
-
const result = await
|
|
170
|
+
const result = await getBetterAuthClient().resetPassword({
|
|
171
171
|
newPassword,
|
|
172
172
|
token,
|
|
173
173
|
});
|
|
@@ -187,6 +187,6 @@ export function useBetterAuth() {
|
|
|
187
187
|
requestPasswordReset,
|
|
188
188
|
resetPassword,
|
|
189
189
|
exchangeForFeathersJWT,
|
|
190
|
-
betterAuthClient,
|
|
190
|
+
betterAuthClient: getBetterAuthClient(),
|
|
191
191
|
};
|
|
192
192
|
}
|
|
@@ -10,11 +10,14 @@ type ObjectId = string;
|
|
|
10
10
|
|
|
11
11
|
// Partner IDs interface
|
|
12
12
|
interface PartnerIds {
|
|
13
|
+
/** @deprecated Privy is no longer used for authentication. This field exists for legacy data compatibility only. */
|
|
13
14
|
privyId?: string;
|
|
14
15
|
thirdwebId?: string;
|
|
15
16
|
}
|
|
16
17
|
|
|
17
|
-
|
|
18
|
+
/**
|
|
19
|
+
* @deprecated Privy is no longer used for authentication. This type exists for legacy data compatibility only.
|
|
20
|
+
*/
|
|
18
21
|
interface PrivyLinkedAccount {
|
|
19
22
|
type: string; // "wallet" | "smart_wallet" | "google_oauth"
|
|
20
23
|
address?: string;
|
|
@@ -76,6 +79,7 @@ interface User {
|
|
|
76
79
|
|
|
77
80
|
// Partner integrations
|
|
78
81
|
partnerIds: PartnerIds;
|
|
82
|
+
/** @deprecated Privy is no longer used for authentication. This field exists for legacy data compatibility only. */
|
|
79
83
|
privyLinkedAccounts?: PrivyLinkedAccount[];
|
|
80
84
|
twProfiles?: TWProfile[];
|
|
81
85
|
}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import type { Chain } from "thirdweb";
|
|
2
|
-
import { Account } from "thirdweb/wallets";
|
|
3
|
-
interface SignInWithB3PrivyProps {
|
|
4
|
-
onError?: (error: Error) => Promise<void>;
|
|
5
|
-
onSuccess: (account: Account) => Promise<void>;
|
|
6
|
-
accessToken?: string;
|
|
7
|
-
chain: Chain;
|
|
8
|
-
}
|
|
9
|
-
export declare function SignInWithB3Privy({ onSuccess, onError, chain }: SignInWithB3PrivyProps): import("react/jsx-runtime").JSX.Element;
|
|
10
|
-
export {};
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.SignInWithB3Privy = SignInWithB3Privy;
|
|
4
|
-
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
|
-
const react_1 = require("../../../../global-account/react");
|
|
6
|
-
const debug_1 = require("../../../../shared/utils/debug");
|
|
7
|
-
const react_2 = require("react");
|
|
8
|
-
const debug = (0, debug_1.debugB3React)("SignInWithB3Privy");
|
|
9
|
-
function SignInWithB3Privy({ onSuccess, onError, chain }) {
|
|
10
|
-
const { partnerId } = (0, react_1.useB3Config)();
|
|
11
|
-
const { isLoading, connectTw, fullToken } = (0, react_1.useHandleConnectWithPrivy)(chain, onSuccess);
|
|
12
|
-
const setIsAuthenticating = (0, react_1.useAuthStore)(state => state.setIsAuthenticating);
|
|
13
|
-
const setIsAuthenticated = (0, react_1.useAuthStore)(state => state.setIsAuthenticated);
|
|
14
|
-
const { logout } = (0, react_1.useAuthentication)(partnerId, { skipAutoConnect: true });
|
|
15
|
-
debug("@@SignInWithB3Privy", {
|
|
16
|
-
isLoading,
|
|
17
|
-
fullToken,
|
|
18
|
-
});
|
|
19
|
-
(0, react_2.useEffect)(() => {
|
|
20
|
-
async function autoConnect() {
|
|
21
|
-
try {
|
|
22
|
-
const connectResult = await connectTw();
|
|
23
|
-
const account = connectResult?.getAccount();
|
|
24
|
-
if (!account) {
|
|
25
|
-
setIsAuthenticated(false);
|
|
26
|
-
return;
|
|
27
|
-
}
|
|
28
|
-
await onSuccess(account);
|
|
29
|
-
setIsAuthenticated(true);
|
|
30
|
-
}
|
|
31
|
-
catch (error) {
|
|
32
|
-
console.error("Failed to connect:", error);
|
|
33
|
-
await onError?.(error);
|
|
34
|
-
await logout();
|
|
35
|
-
setIsAuthenticated(false);
|
|
36
|
-
}
|
|
37
|
-
finally {
|
|
38
|
-
debug("setIsAuthenticating:false:7");
|
|
39
|
-
setIsAuthenticating(false);
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
autoConnect();
|
|
43
|
-
}, [connectTw, onSuccess, onError, setIsAuthenticated, logout, setIsAuthenticating]);
|
|
44
|
-
// Currently we auto login, so we can show loading immediately and the onSuccess will proceed to the next modal
|
|
45
|
-
return ((0, jsx_runtime_1.jsx)("div", { className: "flex aspect-square items-center justify-center p-6", children: (0, jsx_runtime_1.jsx)(react_1.Loading, { variant: "white", size: "lg" }) }));
|
|
46
|
-
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { Chain } from "thirdweb";
|
|
2
|
-
import { Account } from "thirdweb/wallets";
|
|
3
|
-
/**
|
|
4
|
-
* This essentially wraps our useConnect hook to handle the Privy auth flow.
|
|
5
|
-
* Currently, this is for the basement-privy strategy
|
|
6
|
-
*/
|
|
7
|
-
export declare function useHandleConnectWithPrivy(chain?: Chain, onSuccess?: (account: Account) => void): {
|
|
8
|
-
connectTw: () => Promise<import("thirdweb/wallets").Wallet | null | undefined>;
|
|
9
|
-
isLoading: boolean;
|
|
10
|
-
fullToken: string | null;
|
|
11
|
-
};
|
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.useHandleConnectWithPrivy = useHandleConnectWithPrivy;
|
|
4
|
-
const react_1 = require("../../../global-account/react");
|
|
5
|
-
const debug_1 = require("../../../shared/utils/debug");
|
|
6
|
-
const react_auth_1 = require("@privy-io/react-auth");
|
|
7
|
-
const react_2 = require("react");
|
|
8
|
-
const debug = (0, debug_1.debugB3React)("@@b3:useHandleConnectWithPrivy");
|
|
9
|
-
/**
|
|
10
|
-
* This essentially wraps our useConnect hook to handle the Privy auth flow.
|
|
11
|
-
* Currently, this is for the basement-privy strategy
|
|
12
|
-
*/
|
|
13
|
-
function useHandleConnectWithPrivy(chain, onSuccess) {
|
|
14
|
-
const { partnerId } = (0, react_1.useB3Config)();
|
|
15
|
-
if (!chain) {
|
|
16
|
-
throw new Error("Chain is required");
|
|
17
|
-
}
|
|
18
|
-
const { connect } = (0, react_1.useConnect)(partnerId, chain);
|
|
19
|
-
const [isLoading, setIsLoading] = (0, react_2.useState)(true);
|
|
20
|
-
const isConnecting = (0, react_2.useRef)(false);
|
|
21
|
-
const { identityToken } = (0, react_auth_1.useIdentityToken)();
|
|
22
|
-
const { getAccessToken } = (0, react_auth_1.usePrivy)();
|
|
23
|
-
const [fullToken, setFullToken] = (0, react_2.useState)(null);
|
|
24
|
-
const connectTw = (0, react_2.useCallback)(async () => {
|
|
25
|
-
if (isConnecting.current) {
|
|
26
|
-
debug("@@connectTw:skipping:isConnecting", isConnecting.current);
|
|
27
|
-
return;
|
|
28
|
-
}
|
|
29
|
-
setIsLoading(true);
|
|
30
|
-
isConnecting.current = true;
|
|
31
|
-
// Form token
|
|
32
|
-
const accessToken = await getAccessToken();
|
|
33
|
-
const fullToken = `${accessToken}+${identityToken}`;
|
|
34
|
-
setFullToken(fullToken);
|
|
35
|
-
debug("@@connectTw:fullToken", fullToken);
|
|
36
|
-
if (!fullToken)
|
|
37
|
-
throw new Error("Token is not set");
|
|
38
|
-
// Connect to TW via privy
|
|
39
|
-
const wallet = await connect({
|
|
40
|
-
strategy: "auth_endpoint",
|
|
41
|
-
payload: JSON.stringify({
|
|
42
|
-
strategy: "basement",
|
|
43
|
-
accessToken: fullToken,
|
|
44
|
-
}),
|
|
45
|
-
});
|
|
46
|
-
debug("@@useHandleConnectWithPrivy:connect:return", wallet);
|
|
47
|
-
setIsLoading(false);
|
|
48
|
-
// Handle onsuccess & more
|
|
49
|
-
try {
|
|
50
|
-
debug("@@autoLogin:starting", fullToken);
|
|
51
|
-
const account = wallet?.getAccount();
|
|
52
|
-
if (!account) {
|
|
53
|
-
throw new Error("Failed to connect");
|
|
54
|
-
}
|
|
55
|
-
onSuccess?.(account);
|
|
56
|
-
if (!account) {
|
|
57
|
-
throw new Error("Failed to connect");
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
catch (error) {
|
|
61
|
-
console.error("@@Error signing in with Privy", error);
|
|
62
|
-
}
|
|
63
|
-
finally {
|
|
64
|
-
isConnecting.current = false;
|
|
65
|
-
setIsLoading(false);
|
|
66
|
-
}
|
|
67
|
-
return wallet;
|
|
68
|
-
}, [connect, getAccessToken, identityToken, onSuccess]);
|
|
69
|
-
return { connectTw, isLoading, fullToken };
|
|
70
|
-
}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import type { Chain } from "thirdweb";
|
|
2
|
-
import { Account } from "thirdweb/wallets";
|
|
3
|
-
interface SignInWithB3PrivyProps {
|
|
4
|
-
onError?: (error: Error) => Promise<void>;
|
|
5
|
-
onSuccess: (account: Account) => Promise<void>;
|
|
6
|
-
accessToken?: string;
|
|
7
|
-
chain: Chain;
|
|
8
|
-
}
|
|
9
|
-
export declare function SignInWithB3Privy({ onSuccess, onError, chain }: SignInWithB3PrivyProps): import("react/jsx-runtime").JSX.Element;
|
|
10
|
-
export {};
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
import { Loading, useAuthentication, useAuthStore, useB3Config, useHandleConnectWithPrivy, } from "../../../../global-account/react/index.js";
|
|
3
|
-
import { debugB3React } from "../../../../shared/utils/debug.js";
|
|
4
|
-
import { useEffect } from "react";
|
|
5
|
-
const debug = debugB3React("SignInWithB3Privy");
|
|
6
|
-
export function SignInWithB3Privy({ onSuccess, onError, chain }) {
|
|
7
|
-
const { partnerId } = useB3Config();
|
|
8
|
-
const { isLoading, connectTw, fullToken } = useHandleConnectWithPrivy(chain, onSuccess);
|
|
9
|
-
const setIsAuthenticating = useAuthStore(state => state.setIsAuthenticating);
|
|
10
|
-
const setIsAuthenticated = useAuthStore(state => state.setIsAuthenticated);
|
|
11
|
-
const { logout } = useAuthentication(partnerId, { skipAutoConnect: true });
|
|
12
|
-
debug("@@SignInWithB3Privy", {
|
|
13
|
-
isLoading,
|
|
14
|
-
fullToken,
|
|
15
|
-
});
|
|
16
|
-
useEffect(() => {
|
|
17
|
-
async function autoConnect() {
|
|
18
|
-
try {
|
|
19
|
-
const connectResult = await connectTw();
|
|
20
|
-
const account = connectResult?.getAccount();
|
|
21
|
-
if (!account) {
|
|
22
|
-
setIsAuthenticated(false);
|
|
23
|
-
return;
|
|
24
|
-
}
|
|
25
|
-
await onSuccess(account);
|
|
26
|
-
setIsAuthenticated(true);
|
|
27
|
-
}
|
|
28
|
-
catch (error) {
|
|
29
|
-
console.error("Failed to connect:", error);
|
|
30
|
-
await onError?.(error);
|
|
31
|
-
await logout();
|
|
32
|
-
setIsAuthenticated(false);
|
|
33
|
-
}
|
|
34
|
-
finally {
|
|
35
|
-
debug("setIsAuthenticating:false:7");
|
|
36
|
-
setIsAuthenticating(false);
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
autoConnect();
|
|
40
|
-
}, [connectTw, onSuccess, onError, setIsAuthenticated, logout, setIsAuthenticating]);
|
|
41
|
-
// Currently we auto login, so we can show loading immediately and the onSuccess will proceed to the next modal
|
|
42
|
-
return (_jsx("div", { className: "flex aspect-square items-center justify-center p-6", children: _jsx(Loading, { variant: "white", size: "lg" }) }));
|
|
43
|
-
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { Chain } from "thirdweb";
|
|
2
|
-
import { Account } from "thirdweb/wallets";
|
|
3
|
-
/**
|
|
4
|
-
* This essentially wraps our useConnect hook to handle the Privy auth flow.
|
|
5
|
-
* Currently, this is for the basement-privy strategy
|
|
6
|
-
*/
|
|
7
|
-
export declare function useHandleConnectWithPrivy(chain?: Chain, onSuccess?: (account: Account) => void): {
|
|
8
|
-
connectTw: () => Promise<import("thirdweb/wallets").Wallet | null | undefined>;
|
|
9
|
-
isLoading: boolean;
|
|
10
|
-
fullToken: string | null;
|
|
11
|
-
};
|
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
import { useB3Config, useConnect } from "../../../global-account/react/index.js";
|
|
2
|
-
import { debugB3React } from "../../../shared/utils/debug.js";
|
|
3
|
-
import { useIdentityToken, usePrivy } from "@privy-io/react-auth";
|
|
4
|
-
import { useCallback, useRef, useState } from "react";
|
|
5
|
-
const debug = debugB3React("@@b3:useHandleConnectWithPrivy");
|
|
6
|
-
/**
|
|
7
|
-
* This essentially wraps our useConnect hook to handle the Privy auth flow.
|
|
8
|
-
* Currently, this is for the basement-privy strategy
|
|
9
|
-
*/
|
|
10
|
-
export function useHandleConnectWithPrivy(chain, onSuccess) {
|
|
11
|
-
const { partnerId } = useB3Config();
|
|
12
|
-
if (!chain) {
|
|
13
|
-
throw new Error("Chain is required");
|
|
14
|
-
}
|
|
15
|
-
const { connect } = useConnect(partnerId, chain);
|
|
16
|
-
const [isLoading, setIsLoading] = useState(true);
|
|
17
|
-
const isConnecting = useRef(false);
|
|
18
|
-
const { identityToken } = useIdentityToken();
|
|
19
|
-
const { getAccessToken } = usePrivy();
|
|
20
|
-
const [fullToken, setFullToken] = useState(null);
|
|
21
|
-
const connectTw = useCallback(async () => {
|
|
22
|
-
if (isConnecting.current) {
|
|
23
|
-
debug("@@connectTw:skipping:isConnecting", isConnecting.current);
|
|
24
|
-
return;
|
|
25
|
-
}
|
|
26
|
-
setIsLoading(true);
|
|
27
|
-
isConnecting.current = true;
|
|
28
|
-
// Form token
|
|
29
|
-
const accessToken = await getAccessToken();
|
|
30
|
-
const fullToken = `${accessToken}+${identityToken}`;
|
|
31
|
-
setFullToken(fullToken);
|
|
32
|
-
debug("@@connectTw:fullToken", fullToken);
|
|
33
|
-
if (!fullToken)
|
|
34
|
-
throw new Error("Token is not set");
|
|
35
|
-
// Connect to TW via privy
|
|
36
|
-
const wallet = await connect({
|
|
37
|
-
strategy: "auth_endpoint",
|
|
38
|
-
payload: JSON.stringify({
|
|
39
|
-
strategy: "basement",
|
|
40
|
-
accessToken: fullToken,
|
|
41
|
-
}),
|
|
42
|
-
});
|
|
43
|
-
debug("@@useHandleConnectWithPrivy:connect:return", wallet);
|
|
44
|
-
setIsLoading(false);
|
|
45
|
-
// Handle onsuccess & more
|
|
46
|
-
try {
|
|
47
|
-
debug("@@autoLogin:starting", fullToken);
|
|
48
|
-
const account = wallet?.getAccount();
|
|
49
|
-
if (!account) {
|
|
50
|
-
throw new Error("Failed to connect");
|
|
51
|
-
}
|
|
52
|
-
onSuccess?.(account);
|
|
53
|
-
if (!account) {
|
|
54
|
-
throw new Error("Failed to connect");
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
catch (error) {
|
|
58
|
-
console.error("@@Error signing in with Privy", error);
|
|
59
|
-
}
|
|
60
|
-
finally {
|
|
61
|
-
isConnecting.current = false;
|
|
62
|
-
setIsLoading(false);
|
|
63
|
-
}
|
|
64
|
-
return wallet;
|
|
65
|
-
}, [connect, getAccessToken, identityToken, onSuccess]);
|
|
66
|
-
return { connectTw, isLoading, fullToken };
|
|
67
|
-
}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import type { Chain } from "thirdweb";
|
|
2
|
-
import { Account } from "thirdweb/wallets";
|
|
3
|
-
interface SignInWithB3PrivyProps {
|
|
4
|
-
onError?: (error: Error) => Promise<void>;
|
|
5
|
-
onSuccess: (account: Account) => Promise<void>;
|
|
6
|
-
accessToken?: string;
|
|
7
|
-
chain: Chain;
|
|
8
|
-
}
|
|
9
|
-
export declare function SignInWithB3Privy({ onSuccess, onError, chain }: SignInWithB3PrivyProps): import("react/jsx-runtime").JSX.Element;
|
|
10
|
-
export {};
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { Chain } from "thirdweb";
|
|
2
|
-
import { Account } from "thirdweb/wallets";
|
|
3
|
-
/**
|
|
4
|
-
* This essentially wraps our useConnect hook to handle the Privy auth flow.
|
|
5
|
-
* Currently, this is for the basement-privy strategy
|
|
6
|
-
*/
|
|
7
|
-
export declare function useHandleConnectWithPrivy(chain?: Chain, onSuccess?: (account: Account) => void): {
|
|
8
|
-
connectTw: () => Promise<import("thirdweb/wallets").Wallet | null | undefined>;
|
|
9
|
-
isLoading: boolean;
|
|
10
|
-
fullToken: string | null;
|
|
11
|
-
};
|