@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
package/dist/cjs/app.shared.d.ts
CHANGED
|
@@ -1,6 +1,14 @@
|
|
|
1
1
|
import { ClientApplication } from "@b3dotfun/b3-api";
|
|
2
2
|
import { AuthenticationClient } from "@feathersjs/authentication-client";
|
|
3
|
+
/** Default API URL derived from environment variables. */
|
|
3
4
|
export declare const B3_API_URL: string;
|
|
5
|
+
/**
|
|
6
|
+
* Override the B3 API URL at runtime. Called by `B3Provider` when an
|
|
7
|
+
* `apiUrl` prop is provided. Pass `null` to revert to the default.
|
|
8
|
+
*/
|
|
9
|
+
export declare function setB3ApiUrl(url: string | null): void;
|
|
10
|
+
/** Get the current B3 API URL (prefers runtime override, then env var). */
|
|
11
|
+
export declare function getB3ApiUrl(): string;
|
|
4
12
|
export declare const authenticate: (app: ClientApplication, accessToken: string, identityToken: string, params?: Record<string, any>) => Promise<import("@feathersjs/authentication").AuthenticationResult | null>;
|
|
5
13
|
export declare class MyAuthenticationClient extends AuthenticationClient {
|
|
6
14
|
getFromLocation(location: any): Promise<any>;
|
package/dist/cjs/app.shared.js
CHANGED
|
@@ -4,11 +4,30 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.clientOptions = exports.MyAuthenticationClient = exports.authenticate = exports.B3_API_URL = void 0;
|
|
7
|
+
exports.setB3ApiUrl = setB3ApiUrl;
|
|
8
|
+
exports.getB3ApiUrl = getB3ApiUrl;
|
|
7
9
|
const authentication_client_1 = require("@feathersjs/authentication-client");
|
|
8
10
|
const js_cookie_1 = __importDefault(require("js-cookie"));
|
|
9
11
|
const constants_1 = require("./shared/constants");
|
|
10
12
|
const session_duration_1 = require("./shared/utils/session-duration");
|
|
13
|
+
/** Default API URL derived from environment variables. */
|
|
11
14
|
exports.B3_API_URL = process.env.EXPO_PUBLIC_B3_API || process.env.NEXT_PUBLIC_B3_API || process.env.PUBLIC_B3_API || "https://api.b3.fun";
|
|
15
|
+
/**
|
|
16
|
+
* Runtime-overridable API URL. Set by `B3Provider` when an `apiUrl` prop
|
|
17
|
+
* is provided. Falls back to the env-var-derived `B3_API_URL`.
|
|
18
|
+
*/
|
|
19
|
+
let _apiUrlOverride = null;
|
|
20
|
+
/**
|
|
21
|
+
* Override the B3 API URL at runtime. Called by `B3Provider` when an
|
|
22
|
+
* `apiUrl` prop is provided. Pass `null` to revert to the default.
|
|
23
|
+
*/
|
|
24
|
+
function setB3ApiUrl(url) {
|
|
25
|
+
_apiUrlOverride = url;
|
|
26
|
+
}
|
|
27
|
+
/** Get the current B3 API URL (prefers runtime override, then env var). */
|
|
28
|
+
function getB3ApiUrl() {
|
|
29
|
+
return _apiUrlOverride || exports.B3_API_URL;
|
|
30
|
+
}
|
|
12
31
|
const authenticate = async (app, accessToken, identityToken, params) => {
|
|
13
32
|
const fullToken = `${accessToken}+${identityToken}`;
|
|
14
33
|
// Do not authenticate if there is no token
|
|
@@ -940,6 +940,14 @@ export declare function createB3BetterAuthClient(baseURL?: string): {
|
|
|
940
940
|
};
|
|
941
941
|
};
|
|
942
942
|
};
|
|
943
|
+
/** Get the shared BetterAuth client, creating it if needed. */
|
|
944
|
+
export declare function getBetterAuthClient(): B3BetterAuthClient;
|
|
945
|
+
/** Force-recreate the client on next access (e.g. after API URL change). */
|
|
946
|
+
export declare function resetBetterAuthClient(): void;
|
|
947
|
+
/**
|
|
948
|
+
* @deprecated Use `getBetterAuthClient()` instead. This static singleton
|
|
949
|
+
* does not reflect runtime API URL changes via `B3Provider apiUrl` prop.
|
|
950
|
+
*/
|
|
943
951
|
export declare const betterAuthClient: {
|
|
944
952
|
signIn: {
|
|
945
953
|
social: <FetchOptions extends import("@better-auth/core").ClientFetchOption<Partial<{
|
|
@@ -2,16 +2,39 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.betterAuthClient = void 0;
|
|
4
4
|
exports.createB3BetterAuthClient = createB3BetterAuthClient;
|
|
5
|
+
exports.getBetterAuthClient = getBetterAuthClient;
|
|
6
|
+
exports.resetBetterAuthClient = resetBetterAuthClient;
|
|
5
7
|
const client_1 = require("better-auth/client");
|
|
6
8
|
const app_shared_1 = require("../app.shared");
|
|
7
|
-
function createB3BetterAuthClient(baseURL
|
|
9
|
+
function createB3BetterAuthClient(baseURL) {
|
|
8
10
|
return (0, client_1.createAuthClient)({
|
|
9
|
-
baseURL,
|
|
11
|
+
baseURL: baseURL ?? (0, app_shared_1.getB3ApiUrl)(),
|
|
10
12
|
basePath: "/auth",
|
|
11
13
|
fetchOptions: {
|
|
12
14
|
credentials: "include",
|
|
13
15
|
},
|
|
14
16
|
});
|
|
15
17
|
}
|
|
16
|
-
//
|
|
18
|
+
// Lazily-initialized singleton. Recreated when the API URL changes via
|
|
19
|
+
// `resetBetterAuthClient()` (called by B3Provider when `apiUrl` changes).
|
|
20
|
+
let _client = null;
|
|
21
|
+
let _clientUrl = null;
|
|
22
|
+
/** Get the shared BetterAuth client, creating it if needed. */
|
|
23
|
+
function getBetterAuthClient() {
|
|
24
|
+
const url = (0, app_shared_1.getB3ApiUrl)();
|
|
25
|
+
if (!_client || _clientUrl !== url) {
|
|
26
|
+
_client = createB3BetterAuthClient(url);
|
|
27
|
+
_clientUrl = url;
|
|
28
|
+
}
|
|
29
|
+
return _client;
|
|
30
|
+
}
|
|
31
|
+
/** Force-recreate the client on next access (e.g. after API URL change). */
|
|
32
|
+
function resetBetterAuthClient() {
|
|
33
|
+
_client = null;
|
|
34
|
+
_clientUrl = null;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* @deprecated Use `getBetterAuthClient()` instead. This static singleton
|
|
38
|
+
* does not reflect runtime API URL changes via `B3Provider apiUrl` prop.
|
|
39
|
+
*/
|
|
17
40
|
exports.betterAuthClient = createB3BetterAuthClient();
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { ClientApplication } from "@b3dotfun/b3-api";
|
|
2
2
|
export type ClientType = "socket" | "rest";
|
|
3
|
+
/** Reset all cached clients (called when API URL changes). */
|
|
4
|
+
export declare function resetClients(): void;
|
|
3
5
|
/**
|
|
4
6
|
* Sets the active client type and creates the appropriate client
|
|
5
7
|
*
|
|
@@ -4,6 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.authenticateBoth = exports.authenticateWithClient = exports.authenticate = void 0;
|
|
7
|
+
exports.resetClients = resetClients;
|
|
7
8
|
exports.setClientType = setClientType;
|
|
8
9
|
exports.getClient = getClient;
|
|
9
10
|
exports.getClientType = getClientType;
|
|
@@ -21,15 +22,19 @@ let currentClient = null;
|
|
|
21
22
|
// Socket client instance
|
|
22
23
|
let socketClient = null;
|
|
23
24
|
let socketInstance = null;
|
|
25
|
+
let socketClientUrl = null;
|
|
24
26
|
// REST client instance
|
|
25
27
|
let restClient = null;
|
|
28
|
+
let restClientUrl = null;
|
|
26
29
|
/**
|
|
27
30
|
* Creates a socket client
|
|
28
31
|
*/
|
|
29
32
|
function createSocketClient() {
|
|
30
|
-
|
|
31
|
-
|
|
33
|
+
const url = (0, app_shared_1.getB3ApiUrl)();
|
|
34
|
+
if (!socketClient || socketClientUrl !== url) {
|
|
35
|
+
socketInstance = (0, socket_io_client_1.default)(url, { transports: ["websocket"] });
|
|
32
36
|
socketClient = (0, b3_api_1.createClient)((0, socketio_client_1.default)(socketInstance), app_shared_1.clientOptions);
|
|
37
|
+
socketClientUrl = url;
|
|
33
38
|
}
|
|
34
39
|
return socketClient;
|
|
35
40
|
}
|
|
@@ -45,12 +50,22 @@ function resolveFetch() {
|
|
|
45
50
|
return require("cross-fetch").fetch;
|
|
46
51
|
}
|
|
47
52
|
function createRestClient() {
|
|
48
|
-
|
|
49
|
-
|
|
53
|
+
const url = (0, app_shared_1.getB3ApiUrl)();
|
|
54
|
+
if (!restClient || restClientUrl !== url) {
|
|
55
|
+
const connection = (0, rest_client_1.default)(url).fetch(resolveFetch());
|
|
50
56
|
restClient = (0, b3_api_1.createClient)(connection, app_shared_1.clientOptions);
|
|
57
|
+
restClientUrl = url;
|
|
51
58
|
}
|
|
52
59
|
return restClient;
|
|
53
60
|
}
|
|
61
|
+
/** Reset all cached clients (called when API URL changes). */
|
|
62
|
+
function resetClients() {
|
|
63
|
+
socketClient = null;
|
|
64
|
+
socketClientUrl = null;
|
|
65
|
+
restClient = null;
|
|
66
|
+
restClientUrl = null;
|
|
67
|
+
currentClient = null;
|
|
68
|
+
}
|
|
54
69
|
/**
|
|
55
70
|
* Sets the active client type and creates the appropriate client
|
|
56
71
|
*
|
|
@@ -10,7 +10,7 @@ import { ClientType } from "../../../client-manager";
|
|
|
10
10
|
/**
|
|
11
11
|
* Main B3Provider component
|
|
12
12
|
*/
|
|
13
|
-
export declare function B3Provider({ theme, children, accountOverride, environment, automaticallySetFirstEoa, defaultEoaProvider, simDuneApiKey, toaster: _toaster, clientType, rpcUrls, partnerId, stripePublishableKey, onConnect, onLogout, connectors, overrideDefaultConnectors, createClientReferenceId, defaultPermissions, disableBSMNTAuthentication, queryClient, authStrategy, }: {
|
|
13
|
+
export declare function B3Provider({ theme, children, accountOverride, environment, automaticallySetFirstEoa, defaultEoaProvider, simDuneApiKey, toaster: _toaster, clientType, rpcUrls, partnerId, stripePublishableKey, onConnect, onLogout, connectors, overrideDefaultConnectors, createClientReferenceId, defaultPermissions, disableBSMNTAuthentication, queryClient, authStrategy, apiUrl, }: {
|
|
14
14
|
theme: "light" | "dark";
|
|
15
15
|
children: React.ReactNode;
|
|
16
16
|
accountOverride?: Account;
|
|
@@ -39,4 +39,13 @@ export declare function B3Provider({ theme, children, accountOverride, environme
|
|
|
39
39
|
queryClient?: QueryClient;
|
|
40
40
|
/** Auth strategy: "thirdweb" (default, ecosystem wallet) or "better-auth" (email/password via Better Auth) */
|
|
41
41
|
authStrategy?: AuthStrategy;
|
|
42
|
+
/**
|
|
43
|
+
* Override the B3 API URL. When provided, all SDK requests (auth, Feathers,
|
|
44
|
+
* BetterAuth) will use this URL instead of the `NEXT_PUBLIC_B3_API` env var.
|
|
45
|
+
*
|
|
46
|
+
* Useful for local development: pass `http://localhost:3031` to route
|
|
47
|
+
* OAuth callbacks and session checks through your local B3 API.
|
|
48
|
+
* If omitted, defaults to `NEXT_PUBLIC_B3_API` or `https://api.b3.fun`.
|
|
49
|
+
*/
|
|
50
|
+
apiUrl?: string;
|
|
42
51
|
}): import("react/jsx-runtime").JSX.Element;
|
|
@@ -12,6 +12,8 @@ const react_2 = require("../../../../wallet/react");
|
|
|
12
12
|
require("@relayprotocol/relay-kit-ui/styles.css");
|
|
13
13
|
const react_3 = require("react");
|
|
14
14
|
const client_manager_1 = require("../../../client-manager");
|
|
15
|
+
const app_shared_1 = require("../../../../app.shared");
|
|
16
|
+
const better_auth_client_1 = require("../../../better-auth-client");
|
|
15
17
|
const StyleRoot_1 = require("../StyleRoot");
|
|
16
18
|
const index_1 = require("../Toast/index");
|
|
17
19
|
const AuthenticationProvider_1 = __importDefault(require("./AuthenticationProvider"));
|
|
@@ -23,7 +25,19 @@ const LocalSDKProvider_1 = require("./LocalSDKProvider");
|
|
|
23
25
|
*/
|
|
24
26
|
function B3Provider({ theme = "light", children, accountOverride, environment, automaticallySetFirstEoa, defaultEoaProvider, simDuneApiKey,
|
|
25
27
|
// deprecated since v0.0.87
|
|
26
|
-
toaster: _toaster, clientType = "rest", rpcUrls, partnerId, stripePublishableKey, onConnect, onLogout, connectors, overrideDefaultConnectors = false, createClientReferenceId, defaultPermissions, disableBSMNTAuthentication = false, queryClient, authStrategy = "thirdweb", }) {
|
|
28
|
+
toaster: _toaster, clientType = "rest", rpcUrls, partnerId, stripePublishableKey, onConnect, onLogout, connectors, overrideDefaultConnectors = false, createClientReferenceId, defaultPermissions, disableBSMNTAuthentication = false, queryClient, authStrategy = "thirdweb", apiUrl, }) {
|
|
29
|
+
// Override the B3 API URL when the `apiUrl` prop is provided.
|
|
30
|
+
// Must run before client initialization and auth providers mount.
|
|
31
|
+
(0, react_3.useEffect)(() => {
|
|
32
|
+
(0, app_shared_1.setB3ApiUrl)(apiUrl ?? null);
|
|
33
|
+
if (apiUrl) {
|
|
34
|
+
(0, better_auth_client_1.resetBetterAuthClient)();
|
|
35
|
+
(0, client_manager_1.resetClients)();
|
|
36
|
+
}
|
|
37
|
+
return () => {
|
|
38
|
+
(0, app_shared_1.setB3ApiUrl)(null);
|
|
39
|
+
};
|
|
40
|
+
}, [apiUrl]);
|
|
27
41
|
// Initialize Google Analytics on mount
|
|
28
42
|
(0, react_3.useEffect)(() => {
|
|
29
43
|
(0, analytics_1.loadGA4Script)();
|
|
@@ -45,7 +45,7 @@ const BetterAuthProvider = ({ partnerId }) => {
|
|
|
45
45
|
app_1.default.logout = async () => {
|
|
46
46
|
debug("Patched logout: clearing Better Auth session");
|
|
47
47
|
try {
|
|
48
|
-
await better_auth_client_1.
|
|
48
|
+
await (0, better_auth_client_1.getBetterAuthClient)().signOut();
|
|
49
49
|
}
|
|
50
50
|
catch {
|
|
51
51
|
debug("Better Auth signOut failed (non-critical)");
|
|
@@ -79,9 +79,50 @@ const BetterAuthProvider = ({ partnerId }) => {
|
|
|
79
79
|
catch {
|
|
80
80
|
debug("No existing Feathers JWT");
|
|
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
|
+
// Clean the token from the URL immediately (security)
|
|
93
|
+
params.delete("_ba_token");
|
|
94
|
+
const cleanSearch = params.toString();
|
|
95
|
+
const cleanUrl = window.location.pathname + (cleanSearch ? `?${cleanSearch}` : "") + window.location.hash;
|
|
96
|
+
window.history.replaceState({}, "", cleanUrl);
|
|
97
|
+
try {
|
|
98
|
+
const response = await app_1.default.authenticate({
|
|
99
|
+
strategy: "better-auth",
|
|
100
|
+
accessToken: baToken,
|
|
101
|
+
partnerId,
|
|
102
|
+
});
|
|
103
|
+
if (response.accessToken) {
|
|
104
|
+
js_cookie_1.default.set(constants_1.B3_AUTH_COOKIE_NAME, response.accessToken, {
|
|
105
|
+
secure: true,
|
|
106
|
+
sameSite: "Lax",
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
if (response.user) {
|
|
110
|
+
setUser(response.user);
|
|
111
|
+
setIsAuthenticated(true);
|
|
112
|
+
setIsConnected(true);
|
|
113
|
+
}
|
|
114
|
+
debug("_ba_token exchanged for Feathers JWT", { userId: response.user?.userId });
|
|
115
|
+
setIsAuthenticating(false);
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
catch (err) {
|
|
119
|
+
debug("_ba_token exchange failed", err);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
// 3. Check for a Better Auth session via cookie (works when API and frontend
|
|
123
|
+
// share a domain or when cookies aren't partitioned)
|
|
83
124
|
try {
|
|
84
|
-
const session = await better_auth_client_1.
|
|
125
|
+
const session = await (0, better_auth_client_1.getBetterAuthClient)().getSession();
|
|
85
126
|
if (session.data?.session?.token) {
|
|
86
127
|
debug("Better Auth session found, exchanging for Feathers JWT", {
|
|
87
128
|
betterAuthUserId: session.data.user?.id,
|
|
@@ -110,7 +151,7 @@ const BetterAuthProvider = ({ partnerId }) => {
|
|
|
110
151
|
catch {
|
|
111
152
|
debug("No Better Auth session to restore");
|
|
112
153
|
}
|
|
113
|
-
//
|
|
154
|
+
// 4. Nothing found — show login UI
|
|
114
155
|
setIsAuthenticating(false);
|
|
115
156
|
};
|
|
116
157
|
restoreSession();
|
|
@@ -7,7 +7,6 @@ const LoginStepBetterAuth_1 = require("./steps/LoginStepBetterAuth");
|
|
|
7
7
|
const debug_1 = require("../../../../shared/utils/debug");
|
|
8
8
|
const react_2 = require("react");
|
|
9
9
|
const react_3 = require("thirdweb/react");
|
|
10
|
-
const SignInWithB3Privy_1 = require("./SignInWithB3Privy");
|
|
11
10
|
const LoginStep_1 = require("./steps/LoginStep");
|
|
12
11
|
const LoginStepCustom_1 = require("./steps/LoginStepCustom");
|
|
13
12
|
const debug = (0, debug_1.debugB3React)("SignInWithB3Flow");
|
|
@@ -254,10 +253,7 @@ function SignInWithB3Flow({ strategies, onLoginSuccess, onSessionKeySuccess, onE
|
|
|
254
253
|
}
|
|
255
254
|
else {
|
|
256
255
|
// Custom strategy
|
|
257
|
-
if (strategies
|
|
258
|
-
content = (0, jsx_runtime_1.jsx)(SignInWithB3Privy_1.SignInWithB3Privy, { onSuccess: handleLoginSuccess, chain: chain });
|
|
259
|
-
}
|
|
260
|
-
else if (strategies) {
|
|
256
|
+
if (strategies) {
|
|
261
257
|
// Strategies are explicitly provided
|
|
262
258
|
content = ((0, jsx_runtime_1.jsx)(LoginStepCustom_1.LoginStepCustom, { strategies: strategies, chain: chain, onSuccess: handleLoginSuccess, onError: onError, automaticallySetFirstEoa: !!automaticallySetFirstEoa }));
|
|
263
259
|
}
|
|
@@ -2,10 +2,11 @@ import { Chain } from "thirdweb";
|
|
|
2
2
|
import { SingleStepAuthArgsType, Wallet } from "thirdweb/wallets";
|
|
3
3
|
type WalletType = Wallet["id"];
|
|
4
4
|
type StrategyType = SingleStepAuthArgsType["strategy"];
|
|
5
|
-
|
|
5
|
+
declare const customStrategies: readonly ["basement"];
|
|
6
|
+
type CustomStrategyType = (typeof customStrategies)[number];
|
|
6
7
|
type AllowedStrategies = StrategyType | WalletType | CustomStrategyType | "email";
|
|
7
8
|
type NonWalletStrategyType = Exclude<AllowedStrategies, WalletType>;
|
|
8
|
-
export declare const allowedStrategies: readonly ["apple", "google", "github", "x", "discord", "email", "guest", "walletConnect", "io.metamask", "com.coinbase.wallet", "basement"
|
|
9
|
+
export declare const allowedStrategies: readonly ["apple", "google", "github", "x", "discord", "email", "guest", "walletConnect", "io.metamask", "com.coinbase.wallet", "basement"];
|
|
9
10
|
export type AllowedStrategy = (typeof allowedStrategies)[number];
|
|
10
11
|
export declare function isWalletType(strategy: AllowedStrategies): strategy is WalletType;
|
|
11
12
|
export declare function isStrategyType(strategy: AllowedStrategies): strategy is NonWalletStrategyType;
|
|
@@ -5,8 +5,7 @@ exports.isWalletType = isWalletType;
|
|
|
5
5
|
exports.isStrategyType = isStrategyType;
|
|
6
6
|
exports.getConnectOptionsFromStrategy = getConnectOptionsFromStrategy;
|
|
7
7
|
const wallets_1 = require("thirdweb/wallets");
|
|
8
|
-
const customStrategies = ["basement"
|
|
9
|
-
// type CustomStrategy = (typeof customStrategies)[number];
|
|
8
|
+
const customStrategies = ["basement"];
|
|
10
9
|
exports.allowedStrategies = [
|
|
11
10
|
// Auth strategies
|
|
12
11
|
"apple",
|
|
@@ -21,7 +20,6 @@ exports.allowedStrategies = [
|
|
|
21
20
|
"io.metamask",
|
|
22
21
|
"com.coinbase.wallet",
|
|
23
22
|
// Custom strategies
|
|
24
|
-
// TODO: Audit we don't use "privy" directly anymore
|
|
25
23
|
...customStrategies,
|
|
26
24
|
];
|
|
27
25
|
function isWalletType(strategy) {
|
|
@@ -14,7 +14,6 @@ export { PermissionItem } from "./SignInWithB3/components/PermissionItem";
|
|
|
14
14
|
export { WalletRow } from "./SignInWithB3/components/WalletRow";
|
|
15
15
|
export { SignInWithB3 } from "./SignInWithB3/SignInWithB3";
|
|
16
16
|
export { SignInWithB3Flow } from "./SignInWithB3/SignInWithB3Flow";
|
|
17
|
-
export { SignInWithB3Privy } from "./SignInWithB3/SignInWithB3Privy";
|
|
18
17
|
export { LoginStepContainer } from "./SignInWithB3/steps/LoginStep";
|
|
19
18
|
export { getConnectOptionsFromStrategy, isWalletType, type AllowedStrategy } from "./SignInWithB3/utils/signInUtils";
|
|
20
19
|
export { ManageAccount } from "./ManageAccount/ManageAccount";
|
|
@@ -3,9 +3,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.CommandShortcut = exports.CommandSeparator = exports.CommandList = exports.CommandItem = exports.CommandInput = exports.CommandGroup = exports.CommandEmpty = exports.CommandDialog = exports.Command = exports.buttonVariants = exports.Button = exports.badgeVariants = exports.Badge = exports.WalletConnectorIcon = exports.StaggeredFadeLoader = exports.CopyToClipboard = exports.ClientOnly = exports.customButtonVariants = exports.CustomButton = exports.SingleUserSearchSelector = exports.SendERC20Button = exports.SendETHButton = exports.MintButton = exports.AccountAssets = exports.RequestPermissionsButton = exports.RequestPermissions = exports.IPFSMediaRenderer = exports.Send = exports.Deposit = exports.UserAvatar = exports.ManageAccount = exports.isWalletType = exports.getConnectOptionsFromStrategy = exports.LoginStepContainer = exports.
|
|
7
|
-
exports.TooltipProvider = exports.TooltipContent = exports.Tooltip = exports.TextShimmer = exports.TextLoop = exports.TabTrigger = exports.TabsTransitionWrapper = exports.TabsList = exports.TabsContent = exports.Tabs = exports.TabTriggerPrimitive = exports.TabsPrimitive = exports.TabsListPrimitive = exports.TabsContentPrimitive = exports.Skeleton = exports.ShinyButton = exports.ScrollBar = exports.ScrollArea = exports.PopoverTrigger = exports.PopoverContent = exports.Popover = exports.Loading = exports.Input = exports.GlareCardRounded = exports.GlareCard = exports.DropdownMenuTrigger = exports.DropdownMenuSeparator = exports.DropdownMenuItem = exports.DropdownMenuContent = exports.DropdownMenu = exports.DrawerTrigger = exports.DrawerTitle = exports.DrawerPortal = exports.DrawerOverlay = exports.DrawerHeader = exports.DrawerFooter = exports.DrawerDescription = exports.DrawerContent = exports.DrawerClose = exports.Drawer = exports.DialogTrigger = exports.DialogTitle = exports.DialogPortal = exports.DialogOverlay = exports.DialogHeader = exports.DialogFooter = exports.DialogDescription = exports.DialogContent = exports.DialogClose =
|
|
8
|
-
exports.WalletImage = exports.useToastContext = exports.ToastProvider = exports.ToastContainer = exports.Toast = exports.toast = exports.AnimatedLottie = exports.TransitionPanel =
|
|
6
|
+
exports.Dialog = exports.CommandShortcut = exports.CommandSeparator = exports.CommandList = exports.CommandItem = exports.CommandInput = exports.CommandGroup = exports.CommandEmpty = exports.CommandDialog = exports.Command = exports.buttonVariants = exports.Button = exports.badgeVariants = exports.Badge = exports.WalletConnectorIcon = exports.StaggeredFadeLoader = exports.CopyToClipboard = exports.ClientOnly = exports.customButtonVariants = exports.CustomButton = exports.SingleUserSearchSelector = exports.SendERC20Button = exports.SendETHButton = exports.MintButton = exports.AccountAssets = exports.RequestPermissionsButton = exports.RequestPermissions = exports.IPFSMediaRenderer = exports.Send = exports.Deposit = exports.UserAvatar = exports.ManageAccount = exports.isWalletType = exports.getConnectOptionsFromStrategy = exports.LoginStepContainer = exports.SignInWithB3Flow = exports.SignInWithB3 = exports.WalletRow = exports.PermissionItem = exports.AuthButton = exports.BetterAuthVerifyEmail = exports.BetterAuthSignIn = exports.BetterAuthResetPassword = exports.StyleRoot = exports.useB3Config = exports.useB3Account = exports.useB3 = exports.RelayKitProviderWrapper = exports.B3Provider = exports.B3DynamicModal = void 0;
|
|
7
|
+
exports.TooltipTrigger = exports.TooltipProvider = exports.TooltipContent = exports.Tooltip = exports.TextShimmer = exports.TextLoop = exports.TabTrigger = exports.TabsTransitionWrapper = exports.TabsList = exports.TabsContent = exports.Tabs = exports.TabTriggerPrimitive = exports.TabsPrimitive = exports.TabsListPrimitive = exports.TabsContentPrimitive = exports.Skeleton = exports.ShinyButton = exports.ScrollBar = exports.ScrollArea = exports.PopoverTrigger = exports.PopoverContent = exports.Popover = exports.Loading = exports.Input = exports.GlareCardRounded = exports.GlareCard = exports.DropdownMenuTrigger = exports.DropdownMenuSeparator = exports.DropdownMenuItem = exports.DropdownMenuContent = exports.DropdownMenu = exports.DrawerTrigger = exports.DrawerTitle = exports.DrawerPortal = exports.DrawerOverlay = exports.DrawerHeader = exports.DrawerFooter = exports.DrawerDescription = exports.DrawerContent = exports.DrawerClose = exports.Drawer = exports.DialogTrigger = exports.DialogTitle = exports.DialogPortal = exports.DialogOverlay = exports.DialogHeader = exports.DialogFooter = exports.DialogDescription = exports.DialogContent = exports.DialogClose = void 0;
|
|
8
|
+
exports.WalletImage = exports.useToastContext = exports.ToastProvider = exports.ToastContainer = exports.Toast = exports.toast = exports.AnimatedLottie = exports.TransitionPanel = void 0;
|
|
9
9
|
// TODO woj: Barrel file for all components, this might be reason of bundle size issues
|
|
10
10
|
// Core Components
|
|
11
11
|
var B3DynamicModal_1 = require("./B3DynamicModal");
|
|
@@ -39,8 +39,6 @@ var SignInWithB3_1 = require("./SignInWithB3/SignInWithB3");
|
|
|
39
39
|
Object.defineProperty(exports, "SignInWithB3", { enumerable: true, get: function () { return SignInWithB3_1.SignInWithB3; } });
|
|
40
40
|
var SignInWithB3Flow_1 = require("./SignInWithB3/SignInWithB3Flow");
|
|
41
41
|
Object.defineProperty(exports, "SignInWithB3Flow", { enumerable: true, get: function () { return SignInWithB3Flow_1.SignInWithB3Flow; } });
|
|
42
|
-
var SignInWithB3Privy_1 = require("./SignInWithB3/SignInWithB3Privy");
|
|
43
|
-
Object.defineProperty(exports, "SignInWithB3Privy", { enumerable: true, get: function () { return SignInWithB3Privy_1.SignInWithB3Privy; } });
|
|
44
42
|
var LoginStep_1 = require("./SignInWithB3/steps/LoginStep");
|
|
45
43
|
Object.defineProperty(exports, "LoginStepContainer", { enumerable: true, get: function () { return LoginStep_1.LoginStepContainer; } });
|
|
46
44
|
var signInUtils_1 = require("./SignInWithB3/utils/signInUtils");
|
|
@@ -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";
|
|
@@ -14,8 +14,8 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.useTokensFromAddress = exports.useTokenPriceWithFallback = exports.useTokenPrice = exports.useTokenFromUrl = exports.useTokenData = exports.useTokenBalancesByChain = exports.useTokenBalanceDirect = exports.useTokenBalance = exports.useSiwe = exports.useSimCollectibles = exports.useSimTokenBalance = exports.useSimSvmBalance = exports.useSimBalance = exports.useSearchParamsSSR = exports.useRouter = exports.useRemoveSessionKey = exports.useQueryBSMNT = exports.useQueryB3 = exports.useProfileSettings = exports.useProfilePreference = exports.useProfile = exports.useDisplayName = exports.useOneBalance = exports.useNotifications = exports.useNativeBalanceFromRPC = exports.useNativeBalance = exports.useMediaQuery = exports.useIsomorphicLayoutEffect = exports.useIsMobile = exports.useHasMounted = exports.
|
|
18
|
-
exports.useUser = exports.useURLParams =
|
|
17
|
+
exports.useUnifiedChainSwitchAndExecute = exports.useTokensFromAddress = exports.useTokenPriceWithFallback = exports.useTokenPrice = exports.useTokenFromUrl = exports.useTokenData = exports.useTokenBalancesByChain = exports.useTokenBalanceDirect = exports.useTokenBalance = exports.useSiwe = exports.useSimCollectibles = exports.useSimTokenBalance = exports.useSimSvmBalance = exports.useSimBalance = exports.useSearchParamsSSR = exports.useRouter = exports.useRemoveSessionKey = exports.useQueryBSMNT = exports.useQueryB3 = exports.useProfileSettings = exports.useProfilePreference = exports.useProfile = exports.useDisplayName = exports.useOneBalance = exports.useNotifications = exports.useNativeBalanceFromRPC = exports.useNativeBalance = exports.useMediaQuery = exports.useIsomorphicLayoutEffect = exports.useIsMobile = exports.useHasMounted = exports.useGlobalAccount = exports.useGetGeo = exports.useGetAllTWSigners = exports.useFirstEOA = exports.useExchangeRate = exports.useConnect = exports.useClient = exports.useChainSwitchWithAction = exports.useB3EnsName = exports.useB3BalanceFromAddresses = exports.EmailVerificationRequiredError = exports.useBetterAuth = exports.useAuthentication = exports.useAuth = exports.useAnalytics = exports.useAddTWSessionKey = exports.useAccountWallet = exports.useAccountAssets = exports.createWagmiConfig = void 0;
|
|
18
|
+
exports.useUser = exports.useURLParams = void 0;
|
|
19
19
|
var createWagmiConfig_1 = require("../utils/createWagmiConfig");
|
|
20
20
|
Object.defineProperty(exports, "createWagmiConfig", { enumerable: true, get: function () { return createWagmiConfig_1.createWagmiConfig; } });
|
|
21
21
|
var useAccountAssets_1 = require("./useAccountAssets");
|
|
@@ -54,8 +54,6 @@ var useGetGeo_1 = require("./useGetGeo");
|
|
|
54
54
|
Object.defineProperty(exports, "useGetGeo", { enumerable: true, get: function () { return useGetGeo_1.useGetGeo; } });
|
|
55
55
|
var useGlobalAccount_1 = require("./useGlobalAccount");
|
|
56
56
|
Object.defineProperty(exports, "useGlobalAccount", { enumerable: true, get: function () { return useGlobalAccount_1.useGlobalAccount; } });
|
|
57
|
-
var useHandleConnectWithPrivy_1 = require("./useHandleConnectWithPrivy");
|
|
58
|
-
Object.defineProperty(exports, "useHandleConnectWithPrivy", { enumerable: true, get: function () { return useHandleConnectWithPrivy_1.useHandleConnectWithPrivy; } });
|
|
59
57
|
var useHasMounted_1 = require("./useHasMounted");
|
|
60
58
|
Object.defineProperty(exports, "useHasMounted", { enumerable: true, get: function () { return useHasMounted_1.useHasMounted; } });
|
|
61
59
|
var useIsMobile_1 = require("./useIsMobile");
|
|
@@ -57,7 +57,7 @@ function useBetterAuth() {
|
|
|
57
57
|
setHasStartedConnecting(true);
|
|
58
58
|
setIsAuthenticating(true);
|
|
59
59
|
try {
|
|
60
|
-
const result = await better_auth_client_1.
|
|
60
|
+
const result = await (0, better_auth_client_1.getBetterAuthClient)().signIn.email({ email, password });
|
|
61
61
|
if (result.error) {
|
|
62
62
|
throw new Error(result.error.message || "Sign in failed");
|
|
63
63
|
}
|
|
@@ -78,7 +78,7 @@ function useBetterAuth() {
|
|
|
78
78
|
setHasStartedConnecting(true);
|
|
79
79
|
setIsAuthenticating(true);
|
|
80
80
|
try {
|
|
81
|
-
const result = await better_auth_client_1.
|
|
81
|
+
const result = await (0, better_auth_client_1.getBetterAuthClient)().signUp.email({ email, password, name });
|
|
82
82
|
if (result.error) {
|
|
83
83
|
throw new Error(result.error.message || "Sign up failed");
|
|
84
84
|
}
|
|
@@ -87,7 +87,7 @@ function useBetterAuth() {
|
|
|
87
87
|
// requireEmailVerification is enabled — send verification email with
|
|
88
88
|
// a callbackURL Better Auth redirects to after server-side verify.
|
|
89
89
|
// Pass verifyCallbackURL to land on a dedicated confirmation page.
|
|
90
|
-
await better_auth_client_1.
|
|
90
|
+
await (0, better_auth_client_1.getBetterAuthClient)().sendVerificationEmail({
|
|
91
91
|
email,
|
|
92
92
|
callbackURL: verifyCallbackURL || `${window.location.origin}?authStrategy=better-auth`,
|
|
93
93
|
});
|
|
@@ -106,7 +106,7 @@ function useBetterAuth() {
|
|
|
106
106
|
setHasStartedConnecting(true);
|
|
107
107
|
setIsAuthenticating(true);
|
|
108
108
|
try {
|
|
109
|
-
const result = await better_auth_client_1.
|
|
109
|
+
const result = await (0, better_auth_client_1.getBetterAuthClient)().signIn.social({
|
|
110
110
|
provider,
|
|
111
111
|
callbackURL: window.location.href,
|
|
112
112
|
});
|
|
@@ -124,7 +124,7 @@ function useBetterAuth() {
|
|
|
124
124
|
}, [setIsAuthenticating, setHasStartedConnecting]);
|
|
125
125
|
const requestPasswordReset = (0, react_2.useCallback)(async (email, redirectTo) => {
|
|
126
126
|
debug("Requesting password reset", { email });
|
|
127
|
-
const result = await better_auth_client_1.
|
|
127
|
+
const result = await (0, better_auth_client_1.getBetterAuthClient)().requestPasswordReset({
|
|
128
128
|
email,
|
|
129
129
|
redirectTo,
|
|
130
130
|
});
|
|
@@ -136,7 +136,7 @@ function useBetterAuth() {
|
|
|
136
136
|
}, []);
|
|
137
137
|
const resetPassword = (0, react_2.useCallback)(async (newPassword, token) => {
|
|
138
138
|
debug("Resetting password");
|
|
139
|
-
const result = await better_auth_client_1.
|
|
139
|
+
const result = await (0, better_auth_client_1.getBetterAuthClient)().resetPassword({
|
|
140
140
|
newPassword,
|
|
141
141
|
token,
|
|
142
142
|
});
|
|
@@ -153,6 +153,6 @@ function useBetterAuth() {
|
|
|
153
153
|
requestPasswordReset,
|
|
154
154
|
resetPassword,
|
|
155
155
|
exchangeForFeathersJWT,
|
|
156
|
-
betterAuthClient: better_auth_client_1.
|
|
156
|
+
betterAuthClient: (0, better_auth_client_1.getBetterAuthClient)(),
|
|
157
157
|
};
|
|
158
158
|
}
|
|
@@ -3,9 +3,13 @@
|
|
|
3
3
|
*/
|
|
4
4
|
type ObjectId = string;
|
|
5
5
|
interface PartnerIds {
|
|
6
|
+
/** @deprecated Privy is no longer used for authentication. This field exists for legacy data compatibility only. */
|
|
6
7
|
privyId?: string;
|
|
7
8
|
thirdwebId?: string;
|
|
8
9
|
}
|
|
10
|
+
/**
|
|
11
|
+
* @deprecated Privy is no longer used for authentication. This type exists for legacy data compatibility only.
|
|
12
|
+
*/
|
|
9
13
|
interface PrivyLinkedAccount {
|
|
10
14
|
type: string;
|
|
11
15
|
address?: string;
|
|
@@ -45,6 +49,7 @@ interface User {
|
|
|
45
49
|
createdAt: number;
|
|
46
50
|
updatedAt: number;
|
|
47
51
|
partnerIds: PartnerIds;
|
|
52
|
+
/** @deprecated Privy is no longer used for authentication. This field exists for legacy data compatibility only. */
|
|
48
53
|
privyLinkedAccounts?: PrivyLinkedAccount[];
|
|
49
54
|
twProfiles?: TWProfile[];
|
|
50
55
|
}
|
package/dist/esm/app.shared.d.ts
CHANGED
|
@@ -1,6 +1,14 @@
|
|
|
1
1
|
import { ClientApplication } from "@b3dotfun/b3-api";
|
|
2
2
|
import { AuthenticationClient } from "@feathersjs/authentication-client";
|
|
3
|
+
/** Default API URL derived from environment variables. */
|
|
3
4
|
export declare const B3_API_URL: string;
|
|
5
|
+
/**
|
|
6
|
+
* Override the B3 API URL at runtime. Called by `B3Provider` when an
|
|
7
|
+
* `apiUrl` prop is provided. Pass `null` to revert to the default.
|
|
8
|
+
*/
|
|
9
|
+
export declare function setB3ApiUrl(url: string | null): void;
|
|
10
|
+
/** Get the current B3 API URL (prefers runtime override, then env var). */
|
|
11
|
+
export declare function getB3ApiUrl(): string;
|
|
4
12
|
export declare const authenticate: (app: ClientApplication, accessToken: string, identityToken: string, params?: Record<string, any>) => Promise<import("@feathersjs/authentication").AuthenticationResult | null>;
|
|
5
13
|
export declare class MyAuthenticationClient extends AuthenticationClient {
|
|
6
14
|
getFromLocation(location: any): Promise<any>;
|
package/dist/esm/app.shared.js
CHANGED
|
@@ -2,7 +2,24 @@ import { AuthenticationClient } from "@feathersjs/authentication-client";
|
|
|
2
2
|
import Cookies from "js-cookie";
|
|
3
3
|
import { B3_AUTH_COOKIE_NAME } from "./shared/constants/index.js";
|
|
4
4
|
import { getSessionDurationDays } from "./shared/utils/session-duration.js";
|
|
5
|
+
/** Default API URL derived from environment variables. */
|
|
5
6
|
export const B3_API_URL = process.env.EXPO_PUBLIC_B3_API || process.env.NEXT_PUBLIC_B3_API || process.env.PUBLIC_B3_API || "https://api.b3.fun";
|
|
7
|
+
/**
|
|
8
|
+
* Runtime-overridable API URL. Set by `B3Provider` when an `apiUrl` prop
|
|
9
|
+
* is provided. Falls back to the env-var-derived `B3_API_URL`.
|
|
10
|
+
*/
|
|
11
|
+
let _apiUrlOverride = null;
|
|
12
|
+
/**
|
|
13
|
+
* Override the B3 API URL at runtime. Called by `B3Provider` when an
|
|
14
|
+
* `apiUrl` prop is provided. Pass `null` to revert to the default.
|
|
15
|
+
*/
|
|
16
|
+
export function setB3ApiUrl(url) {
|
|
17
|
+
_apiUrlOverride = url;
|
|
18
|
+
}
|
|
19
|
+
/** Get the current B3 API URL (prefers runtime override, then env var). */
|
|
20
|
+
export function getB3ApiUrl() {
|
|
21
|
+
return _apiUrlOverride || B3_API_URL;
|
|
22
|
+
}
|
|
6
23
|
export const authenticate = async (app, accessToken, identityToken, params) => {
|
|
7
24
|
const fullToken = `${accessToken}+${identityToken}`;
|
|
8
25
|
// Do not authenticate if there is no token
|
|
@@ -940,6 +940,14 @@ export declare function createB3BetterAuthClient(baseURL?: string): {
|
|
|
940
940
|
};
|
|
941
941
|
};
|
|
942
942
|
};
|
|
943
|
+
/** Get the shared BetterAuth client, creating it if needed. */
|
|
944
|
+
export declare function getBetterAuthClient(): B3BetterAuthClient;
|
|
945
|
+
/** Force-recreate the client on next access (e.g. after API URL change). */
|
|
946
|
+
export declare function resetBetterAuthClient(): void;
|
|
947
|
+
/**
|
|
948
|
+
* @deprecated Use `getBetterAuthClient()` instead. This static singleton
|
|
949
|
+
* does not reflect runtime API URL changes via `B3Provider apiUrl` prop.
|
|
950
|
+
*/
|
|
943
951
|
export declare const betterAuthClient: {
|
|
944
952
|
signIn: {
|
|
945
953
|
social: <FetchOptions extends import("@better-auth/core").ClientFetchOption<Partial<{
|
|
@@ -1,13 +1,34 @@
|
|
|
1
1
|
import { createAuthClient } from "better-auth/client";
|
|
2
|
-
import {
|
|
3
|
-
export function createB3BetterAuthClient(baseURL
|
|
2
|
+
import { getB3ApiUrl } from "../app.shared.js";
|
|
3
|
+
export function createB3BetterAuthClient(baseURL) {
|
|
4
4
|
return createAuthClient({
|
|
5
|
-
baseURL,
|
|
5
|
+
baseURL: baseURL ?? getB3ApiUrl(),
|
|
6
6
|
basePath: "/auth",
|
|
7
7
|
fetchOptions: {
|
|
8
8
|
credentials: "include",
|
|
9
9
|
},
|
|
10
10
|
});
|
|
11
11
|
}
|
|
12
|
-
//
|
|
12
|
+
// Lazily-initialized singleton. Recreated when the API URL changes via
|
|
13
|
+
// `resetBetterAuthClient()` (called by B3Provider when `apiUrl` changes).
|
|
14
|
+
let _client = null;
|
|
15
|
+
let _clientUrl = null;
|
|
16
|
+
/** Get the shared BetterAuth client, creating it if needed. */
|
|
17
|
+
export function getBetterAuthClient() {
|
|
18
|
+
const url = getB3ApiUrl();
|
|
19
|
+
if (!_client || _clientUrl !== url) {
|
|
20
|
+
_client = createB3BetterAuthClient(url);
|
|
21
|
+
_clientUrl = url;
|
|
22
|
+
}
|
|
23
|
+
return _client;
|
|
24
|
+
}
|
|
25
|
+
/** Force-recreate the client on next access (e.g. after API URL change). */
|
|
26
|
+
export function resetBetterAuthClient() {
|
|
27
|
+
_client = null;
|
|
28
|
+
_clientUrl = null;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* @deprecated Use `getBetterAuthClient()` instead. This static singleton
|
|
32
|
+
* does not reflect runtime API URL changes via `B3Provider apiUrl` prop.
|
|
33
|
+
*/
|
|
13
34
|
export const betterAuthClient = createB3BetterAuthClient();
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { ClientApplication } from "@b3dotfun/b3-api";
|
|
2
2
|
export type ClientType = "socket" | "rest";
|
|
3
|
+
/** Reset all cached clients (called when API URL changes). */
|
|
4
|
+
export declare function resetClients(): void;
|
|
3
5
|
/**
|
|
4
6
|
* Sets the active client type and creates the appropriate client
|
|
5
7
|
*
|