better-auth 1.6.18 → 1.6.19

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.
@@ -27,11 +27,11 @@ async function sendVerificationEmailFn(ctx, user) {
27
27
  const token = await createEmailVerificationToken(ctx.context.secret, user.email, void 0, ctx.context.options.emailVerification?.expiresIn);
28
28
  const callbackURL = ctx.body.callbackURL ? encodeURIComponent(ctx.body.callbackURL) : encodeURIComponent("/");
29
29
  const url = `${ctx.context.baseURL}/verify-email?token=${token}&callbackURL=${callbackURL}`;
30
- await ctx.context.runInBackgroundOrAwait(ctx.context.options.emailVerification.sendVerificationEmail({
30
+ await ctx.context.options.emailVerification.sendVerificationEmail({
31
31
  user,
32
32
  url,
33
33
  token
34
- }, ctx.request?.clone()));
34
+ }, ctx.request);
35
35
  }
36
36
  const sendVerificationEmail = createAuthEndpoint("/send-verification-email", {
37
37
  method: "POST",
@@ -94,12 +94,25 @@ const sendVerificationEmail = createAuthEndpoint("/send-verification-email", {
94
94
  const { email } = ctx.body;
95
95
  const session = await getSessionFromCtx(ctx);
96
96
  if (!session) {
97
+ /**
98
+ * Enforce a constant-time floor so an attacker cannot distinguish
99
+ * "email not found / already verified" (fast local JWT sign) from
100
+ * "email found and unverified" (slow external email-send) by
101
+ * comparing response times.
102
+ */
103
+ const MINIMUM_MS = 500;
104
+ const start = Date.now();
97
105
  const user = await ctx.context.internalAdapter.findUserByEmail(email);
98
- if (!user || user.user.emailVerified) {
99
- await createEmailVerificationToken(ctx.context.secret, email, void 0, ctx.context.options.emailVerification?.expiresIn);
100
- return ctx.json({ status: true });
106
+ let error;
107
+ if (!user || user.user.emailVerified) await createEmailVerificationToken(ctx.context.secret, email, void 0, ctx.context.options.emailVerification?.expiresIn);
108
+ else try {
109
+ await sendVerificationEmailFn(ctx, user.user);
110
+ } catch (e) {
111
+ error = e;
101
112
  }
102
- await sendVerificationEmailFn(ctx, user.user);
113
+ const remaining = MINIMUM_MS - (Date.now() - start);
114
+ if (remaining > 0) await new Promise((resolve) => setTimeout(resolve, remaining));
115
+ if (error) throw error;
103
116
  return ctx.json({ status: true });
104
117
  }
105
118
  if (session?.user.email.toLowerCase() !== email.toLowerCase()) throw APIError.from("BAD_REQUEST", BASE_ERROR_CODES.EMAIL_MISMATCH);
@@ -56,10 +56,7 @@ const getSession = () => createAuthEndpoint("/get-session", {
56
56
  },
57
57
  expiresAt: payload.exp ? payload.exp * 1e3 : Date.now()
58
58
  };
59
- else {
60
- expireCookie(ctx, ctx.context.authCookies.sessionData);
61
- return ctx.json(null);
62
- }
59
+ else expireCookie(ctx, ctx.context.authCookies.sessionData);
63
60
  } else if (strategy === "jwt") {
64
61
  const payload = await verifyJWT(sessionDataCookie, ctx.context.secret);
65
62
  if (payload && payload.session && payload.user) sessionDataPayload = {
@@ -71,20 +68,14 @@ const getSession = () => createAuthEndpoint("/get-session", {
71
68
  },
72
69
  expiresAt: payload.exp ? payload.exp * 1e3 : Date.now()
73
70
  };
74
- else {
75
- expireCookie(ctx, ctx.context.authCookies.sessionData);
76
- return ctx.json(null);
77
- }
71
+ else expireCookie(ctx, ctx.context.authCookies.sessionData);
78
72
  } else {
79
73
  const parsed = safeJSONParse(binary.decode(base64Url.decode(sessionDataCookie)));
80
74
  if (parsed) if (await createHMAC("SHA-256", "base64urlnopad").verify(ctx.context.secret, JSON.stringify({
81
75
  ...parsed.session,
82
76
  expiresAt: parsed.expiresAt
83
77
  }), parsed.signature)) sessionDataPayload = parsed;
84
- else {
85
- expireCookie(ctx, ctx.context.authCookies.sessionData);
86
- return ctx.json(null);
87
- }
78
+ else expireCookie(ctx, ctx.context.authCookies.sessionData);
88
79
  }
89
80
  }
90
81
  const dontRememberMe = await ctx.getSignedCookie(ctx.context.authCookies.dontRememberToken.name, ctx.context.secret);
@@ -0,0 +1,86 @@
1
+ import { BetterAuthClientOptions, ClientAtomListener } from "@better-auth/core";
2
+ import { WritableAtom } from "nanostores";
3
+ import * as _better_fetch_fetch0 from "@better-fetch/fetch";
4
+
5
+ //#region src/client/config.d.ts
6
+ declare const getClientConfig: (options?: BetterAuthClientOptions | undefined, loadEnv?: boolean | undefined) => {
7
+ readonly baseURL: string;
8
+ pluginsActions: Record<string, any>;
9
+ pluginsAtoms: Record<string, WritableAtom<any>>;
10
+ pluginPathMethods: Record<string, "GET" | "POST">;
11
+ atomListeners: ClientAtomListener[];
12
+ $fetch: _better_fetch_fetch0.BetterFetch<{
13
+ plugins: (_better_fetch_fetch0.BetterFetchPlugin<Record<string, any>> | {
14
+ id: string;
15
+ name: string;
16
+ hooks: {
17
+ onSuccess(context: _better_fetch_fetch0.SuccessContext<any>): void;
18
+ };
19
+ } | {
20
+ id: string;
21
+ name: string;
22
+ hooks: {
23
+ onSuccess: ((context: _better_fetch_fetch0.SuccessContext<any>) => Promise<void> | void) | undefined;
24
+ onError: ((context: _better_fetch_fetch0.ErrorContext) => Promise<void> | void) | undefined;
25
+ onRequest: (<T extends Record<string, any>>(context: _better_fetch_fetch0.RequestContext<T>) => Promise<_better_fetch_fetch0.RequestContext | void> | _better_fetch_fetch0.RequestContext | void) | undefined;
26
+ onResponse: ((context: _better_fetch_fetch0.ResponseContext) => Promise<Response | void | _better_fetch_fetch0.ResponseContext> | Response | _better_fetch_fetch0.ResponseContext | void) | undefined;
27
+ };
28
+ })[];
29
+ priority?: RequestPriority | undefined;
30
+ cache?: RequestCache | undefined;
31
+ credentials?: RequestCredentials;
32
+ integrity?: string | undefined;
33
+ keepalive?: boolean | undefined;
34
+ method: string;
35
+ mode?: RequestMode | undefined;
36
+ redirect?: RequestRedirect | undefined;
37
+ referrer?: string | undefined;
38
+ referrerPolicy?: ReferrerPolicy | undefined;
39
+ signal?: (AbortSignal | null) | undefined;
40
+ window?: null | undefined;
41
+ onRetry?: ((response: _better_fetch_fetch0.ResponseContext) => Promise<void> | void) | undefined;
42
+ hookOptions?: {
43
+ cloneResponse?: boolean;
44
+ } | undefined;
45
+ timeout?: number | undefined;
46
+ customFetchImpl: _better_fetch_fetch0.FetchEsque;
47
+ baseURL: string;
48
+ throw?: boolean | undefined;
49
+ auth?: ({
50
+ type: "Bearer";
51
+ token: string | Promise<string | undefined> | (() => string | Promise<string | undefined> | undefined) | undefined;
52
+ } | {
53
+ type: "Basic";
54
+ username: string | (() => string | undefined) | undefined;
55
+ password: string | (() => string | undefined) | undefined;
56
+ } | {
57
+ type: "Custom";
58
+ prefix: string | (() => string | undefined) | undefined;
59
+ value: string | (() => string | undefined) | undefined;
60
+ }) | undefined;
61
+ headers?: {} | {
62
+ [x: string]: string | undefined;
63
+ accept?: ((string & {}) | "application/json" | "text/plain" | "application/octet-stream") | undefined;
64
+ "content-type"?: ((string & {}) | "application/x-www-form-urlencoded" | "application/json" | "text/plain" | "application/octet-stream" | "multipart/form-data") | undefined;
65
+ authorization?: ((string & {}) | `Bearer ${string}` | `Basic ${string}`) | undefined;
66
+ } | undefined;
67
+ body?: any;
68
+ query?: any;
69
+ params?: any;
70
+ duplex?: "full" | "half" | undefined;
71
+ jsonParser: (text: string) => Promise<any> | any;
72
+ retry?: _better_fetch_fetch0.RetryOptions | undefined;
73
+ retryAttempt?: number | undefined;
74
+ output?: (_better_fetch_fetch0.StandardSchemaV1 | typeof Blob | typeof File) | undefined;
75
+ errorSchema?: _better_fetch_fetch0.StandardSchemaV1 | undefined;
76
+ disableValidation?: boolean | undefined;
77
+ disableSignal?: boolean | undefined;
78
+ }, unknown, unknown, {}>;
79
+ $store: {
80
+ notify: (signal?: (Omit<string, "$sessionSignal"> | "$sessionSignal") | undefined) => void;
81
+ listen: (signal: Omit<string, "$sessionSignal"> | "$sessionSignal", listener: (value: boolean, oldValue?: boolean | undefined) => void) => void;
82
+ atoms: Record<string, WritableAtom<any>>;
83
+ };
84
+ };
85
+ //#endregion
86
+ export { getClientConfig };
@@ -1,11 +1,10 @@
1
1
  import { ExtractPluginField, HasRequiredKeys, InferPluginFieldFromTuple, IsAny, OverrideMerge, Prettify, PrettifyDeep, RequiredKeysOf, StripEmptyObjects, UnionToIntersection } from "../../types/helper.mjs";
2
2
  import { InferActions, InferClientAPI, InferErrorCodes, IsSignal, SessionQueryParams } from "../types.mjs";
3
+ import { getClientConfig } from "../config.mjs";
3
4
  import { useStore } from "./lynx-store.mjs";
4
5
  import { BetterAuthClientOptions } from "@better-auth/core";
5
6
  import { BASE_ERROR_CODES } from "@better-auth/core/error";
6
- import * as nanostores from "nanostores";
7
- import * as _better_fetch_fetch0 from "@better-fetch/fetch";
8
- import { BetterFetchError } from "@better-fetch/fetch";
7
+ import { BetterFetchError, BetterFetchResponse } from "@better-fetch/fetch";
9
8
  export * from "nanostores";
10
9
  export * from "@better-fetch/fetch";
11
10
 
@@ -15,21 +14,16 @@ type InferResolvedHooks<O extends BetterAuthClientOptions> = O extends {
15
14
  } ? UnionToIntersection<Plugin extends {
16
15
  getAtoms?: infer GetAtoms;
17
16
  } ? GetAtoms extends ((fetch: any) => infer Atoms) ? Atoms extends Record<string, any> ? { [key in keyof Atoms as IsSignal<key> extends true ? never : key extends string ? `use${Capitalize<key>}` : never]: () => ReturnType<Atoms[key]["get"]> } : {} : {} : {}> : {};
18
- declare function createAuthClient<Option extends BetterAuthClientOptions>(options?: Option | undefined): UnionToIntersection<InferResolvedHooks<Option>> & InferClientAPI<Option> & InferActions<Option> & {
17
+ type ClientConfig = ReturnType<typeof getClientConfig>;
18
+ type ClientSession<Option extends BetterAuthClientOptions> = InferClientAPI<Option> extends {
19
+ getSession: () => Promise<infer Res>;
20
+ } ? Res extends BetterFetchResponse<infer S> ? S : Res : never;
21
+ /**
22
+ * Lynx client returned by `createAuthClient`.
23
+ */
24
+ type LynxAuthClient<Option extends BetterAuthClientOptions> = UnionToIntersection<InferResolvedHooks<Option>> & InferClientAPI<Option> & InferActions<Option> & {
19
25
  useSession: () => {
20
- data: InferClientAPI<Option> extends {
21
- getSession: () => Promise<infer Res>;
22
- } ? Res extends {
23
- data: null;
24
- error: {
25
- message?: string | undefined;
26
- status: number;
27
- statusText: string;
28
- };
29
- } | {
30
- data: infer S;
31
- error: null;
32
- } ? S : Res : never;
26
+ data: ClientSession<Option>;
33
27
  isPending: boolean;
34
28
  error: BetterFetchError | null;
35
29
  refetch: (queryParams?: {
@@ -37,93 +31,12 @@ declare function createAuthClient<Option extends BetterAuthClientOptions>(option
37
31
  } | undefined) => Promise<void>;
38
32
  };
39
33
  $Infer: {
40
- Session: NonNullable<InferClientAPI<Option> extends {
41
- getSession: () => Promise<infer Res>;
42
- } ? Res extends {
43
- data: null;
44
- error: {
45
- message?: string | undefined;
46
- status: number;
47
- statusText: string;
48
- };
49
- } | {
50
- data: infer S;
51
- error: null;
52
- } ? S : Res : never>;
53
- };
54
- $fetch: _better_fetch_fetch0.BetterFetch<{
55
- plugins: (_better_fetch_fetch0.BetterFetchPlugin<Record<string, any>> | {
56
- id: string;
57
- name: string;
58
- hooks: {
59
- onSuccess(context: _better_fetch_fetch0.SuccessContext<any>): void;
60
- };
61
- } | {
62
- id: string;
63
- name: string;
64
- hooks: {
65
- onSuccess: ((context: _better_fetch_fetch0.SuccessContext<any>) => Promise<void> | void) | undefined;
66
- onError: ((context: _better_fetch_fetch0.ErrorContext) => Promise<void> | void) | undefined;
67
- onRequest: (<T extends Record<string, any>>(context: _better_fetch_fetch0.RequestContext<T>) => Promise<_better_fetch_fetch0.RequestContext | void> | _better_fetch_fetch0.RequestContext | void) | undefined;
68
- onResponse: ((context: _better_fetch_fetch0.ResponseContext) => Promise<Response | void | _better_fetch_fetch0.ResponseContext> | Response | _better_fetch_fetch0.ResponseContext | void) | undefined;
69
- };
70
- })[];
71
- priority?: RequestPriority | undefined;
72
- cache?: RequestCache | undefined;
73
- credentials?: RequestCredentials;
74
- integrity?: string | undefined;
75
- keepalive?: boolean | undefined;
76
- method: string;
77
- mode?: RequestMode | undefined;
78
- redirect?: RequestRedirect | undefined;
79
- referrer?: string | undefined;
80
- referrerPolicy?: ReferrerPolicy | undefined;
81
- signal?: (AbortSignal | null) | undefined;
82
- window?: null | undefined;
83
- onRetry?: ((response: _better_fetch_fetch0.ResponseContext) => Promise<void> | void) | undefined;
84
- hookOptions?: {
85
- cloneResponse?: boolean;
86
- } | undefined;
87
- timeout?: number | undefined;
88
- customFetchImpl: _better_fetch_fetch0.FetchEsque;
89
- baseURL: string;
90
- throw?: boolean | undefined;
91
- auth?: ({
92
- type: "Bearer";
93
- token: string | Promise<string | undefined> | (() => string | Promise<string | undefined> | undefined) | undefined;
94
- } | {
95
- type: "Basic";
96
- username: string | (() => string | undefined) | undefined;
97
- password: string | (() => string | undefined) | undefined;
98
- } | {
99
- type: "Custom";
100
- prefix: string | (() => string | undefined) | undefined;
101
- value: string | (() => string | undefined) | undefined;
102
- }) | undefined;
103
- headers?: {} | {
104
- [x: string]: string | undefined;
105
- accept?: ((string & {}) | "application/json" | "text/plain" | "application/octet-stream") | undefined;
106
- "content-type"?: ((string & {}) | "application/x-www-form-urlencoded" | "application/json" | "text/plain" | "application/octet-stream" | "multipart/form-data") | undefined;
107
- authorization?: ((string & {}) | `Bearer ${string}` | `Basic ${string}`) | undefined;
108
- } | undefined;
109
- body?: any;
110
- query?: any;
111
- params?: any;
112
- duplex?: "full" | "half" | undefined;
113
- jsonParser: (text: string) => Promise<any> | any;
114
- retry?: _better_fetch_fetch0.RetryOptions | undefined;
115
- retryAttempt?: number | undefined;
116
- output?: (_better_fetch_fetch0.StandardSchemaV1 | typeof Blob | typeof File) | undefined;
117
- errorSchema?: _better_fetch_fetch0.StandardSchemaV1 | undefined;
118
- disableValidation?: boolean | undefined;
119
- disableSignal?: boolean | undefined;
120
- }, unknown, unknown, {}>;
121
- $store: {
122
- notify: (signal?: (Omit<string, "$sessionSignal"> | "$sessionSignal") | undefined) => void;
123
- listen: (signal: Omit<string, "$sessionSignal"> | "$sessionSignal", listener: (value: boolean, oldValue?: boolean | undefined) => void) => void;
124
- atoms: Record<string, nanostores.WritableAtom<any>>;
34
+ Session: NonNullable<ClientSession<Option>>;
125
35
  };
36
+ $fetch: ClientConfig["$fetch"];
37
+ $store: ClientConfig["$store"];
126
38
  $ERROR_CODES: PrettifyDeep<InferErrorCodes<Option> & typeof BASE_ERROR_CODES>;
127
39
  };
40
+ declare function createAuthClient<Option extends BetterAuthClientOptions>(options?: Option | undefined): LynxAuthClient<Option>;
128
41
  //#endregion
129
- export { ExtractPluginField, HasRequiredKeys, InferPluginFieldFromTuple, IsAny, OverrideMerge, Prettify, PrettifyDeep, RequiredKeysOf, StripEmptyObjects, type UnionToIntersection, createAuthClient, useStore };
42
+ export { ExtractPluginField, HasRequiredKeys, InferPluginFieldFromTuple, IsAny, LynxAuthClient, OverrideMerge, Prettify, PrettifyDeep, RequiredKeysOf, StripEmptyObjects, type UnionToIntersection, createAuthClient, useStore };
@@ -1,11 +1,10 @@
1
1
  import { ExtractPluginField, HasRequiredKeys, InferPluginFieldFromTuple, IsAny, OverrideMerge, Prettify, PrettifyDeep, RequiredKeysOf, StripEmptyObjects, UnionToIntersection } from "../../types/helper.mjs";
2
2
  import { InferActions, InferClientAPI, InferErrorCodes, IsSignal, SessionQueryParams } from "../types.mjs";
3
+ import { getClientConfig } from "../config.mjs";
3
4
  import { useStore } from "./react-store.mjs";
4
5
  import { BetterAuthClientOptions } from "@better-auth/core";
5
6
  import { BASE_ERROR_CODES } from "@better-auth/core/error";
6
- import * as nanostores from "nanostores";
7
- import * as _better_fetch_fetch0 from "@better-fetch/fetch";
8
- import { BetterFetchError } from "@better-fetch/fetch";
7
+ import { BetterFetchError, BetterFetchResponse } from "@better-fetch/fetch";
9
8
  export * from "nanostores";
10
9
  export * from "@better-fetch/fetch";
11
10
 
@@ -15,21 +14,16 @@ type InferResolvedHooks<O extends BetterAuthClientOptions> = O extends {
15
14
  } ? UnionToIntersection<Plugin extends {
16
15
  getAtoms?: infer GetAtoms;
17
16
  } ? GetAtoms extends ((fetch: any) => infer Atoms) ? Atoms extends Record<string, any> ? { [key in keyof Atoms as IsSignal<key> extends true ? never : key extends string ? `use${Capitalize<key>}` : never]: () => ReturnType<Atoms[key]["get"]> } : {} : {} : {}> : {};
18
- declare function createAuthClient<Option extends BetterAuthClientOptions>(options?: Option | undefined): UnionToIntersection<InferResolvedHooks<Option>> & InferClientAPI<Option> & InferActions<Option> & {
17
+ type ClientConfig = ReturnType<typeof getClientConfig>;
18
+ type ClientSession<Option extends BetterAuthClientOptions> = InferClientAPI<Option> extends {
19
+ getSession: () => Promise<infer Res>;
20
+ } ? Res extends BetterFetchResponse<infer S> ? S : Res : never;
21
+ /**
22
+ * React client returned by `createAuthClient`.
23
+ */
24
+ type ReactAuthClient<Option extends BetterAuthClientOptions> = UnionToIntersection<InferResolvedHooks<Option>> & InferClientAPI<Option> & InferActions<Option> & {
19
25
  useSession: () => {
20
- data: InferClientAPI<Option> extends {
21
- getSession: () => Promise<infer Res>;
22
- } ? Res extends {
23
- data: null;
24
- error: {
25
- message?: string | undefined;
26
- status: number;
27
- statusText: string;
28
- };
29
- } | {
30
- data: infer S;
31
- error: null;
32
- } ? S : Res : never;
26
+ data: ClientSession<Option>;
33
27
  isPending: boolean;
34
28
  isRefetching: boolean;
35
29
  error: BetterFetchError | null;
@@ -38,93 +32,12 @@ declare function createAuthClient<Option extends BetterAuthClientOptions>(option
38
32
  } | undefined) => Promise<void>;
39
33
  };
40
34
  $Infer: {
41
- Session: NonNullable<InferClientAPI<Option> extends {
42
- getSession: () => Promise<infer Res>;
43
- } ? Res extends {
44
- data: null;
45
- error: {
46
- message?: string | undefined;
47
- status: number;
48
- statusText: string;
49
- };
50
- } | {
51
- data: infer S;
52
- error: null;
53
- } ? S : Res : never>;
54
- };
55
- $fetch: _better_fetch_fetch0.BetterFetch<{
56
- plugins: (_better_fetch_fetch0.BetterFetchPlugin<Record<string, any>> | {
57
- id: string;
58
- name: string;
59
- hooks: {
60
- onSuccess(context: _better_fetch_fetch0.SuccessContext<any>): void;
61
- };
62
- } | {
63
- id: string;
64
- name: string;
65
- hooks: {
66
- onSuccess: ((context: _better_fetch_fetch0.SuccessContext<any>) => Promise<void> | void) | undefined;
67
- onError: ((context: _better_fetch_fetch0.ErrorContext) => Promise<void> | void) | undefined;
68
- onRequest: (<T extends Record<string, any>>(context: _better_fetch_fetch0.RequestContext<T>) => Promise<_better_fetch_fetch0.RequestContext | void> | _better_fetch_fetch0.RequestContext | void) | undefined;
69
- onResponse: ((context: _better_fetch_fetch0.ResponseContext) => Promise<Response | void | _better_fetch_fetch0.ResponseContext> | Response | _better_fetch_fetch0.ResponseContext | void) | undefined;
70
- };
71
- })[];
72
- priority?: RequestPriority | undefined;
73
- cache?: RequestCache | undefined;
74
- credentials?: RequestCredentials;
75
- integrity?: string | undefined;
76
- keepalive?: boolean | undefined;
77
- method: string;
78
- mode?: RequestMode | undefined;
79
- redirect?: RequestRedirect | undefined;
80
- referrer?: string | undefined;
81
- referrerPolicy?: ReferrerPolicy | undefined;
82
- signal?: (AbortSignal | null) | undefined;
83
- window?: null | undefined;
84
- onRetry?: ((response: _better_fetch_fetch0.ResponseContext) => Promise<void> | void) | undefined;
85
- hookOptions?: {
86
- cloneResponse?: boolean;
87
- } | undefined;
88
- timeout?: number | undefined;
89
- customFetchImpl: _better_fetch_fetch0.FetchEsque;
90
- baseURL: string;
91
- throw?: boolean | undefined;
92
- auth?: ({
93
- type: "Bearer";
94
- token: string | Promise<string | undefined> | (() => string | Promise<string | undefined> | undefined) | undefined;
95
- } | {
96
- type: "Basic";
97
- username: string | (() => string | undefined) | undefined;
98
- password: string | (() => string | undefined) | undefined;
99
- } | {
100
- type: "Custom";
101
- prefix: string | (() => string | undefined) | undefined;
102
- value: string | (() => string | undefined) | undefined;
103
- }) | undefined;
104
- headers?: {} | {
105
- [x: string]: string | undefined;
106
- accept?: ((string & {}) | "application/json" | "text/plain" | "application/octet-stream") | undefined;
107
- "content-type"?: ((string & {}) | "application/x-www-form-urlencoded" | "application/json" | "text/plain" | "application/octet-stream" | "multipart/form-data") | undefined;
108
- authorization?: ((string & {}) | `Bearer ${string}` | `Basic ${string}`) | undefined;
109
- } | undefined;
110
- body?: any;
111
- query?: any;
112
- params?: any;
113
- duplex?: "full" | "half" | undefined;
114
- jsonParser: (text: string) => Promise<any> | any;
115
- retry?: _better_fetch_fetch0.RetryOptions | undefined;
116
- retryAttempt?: number | undefined;
117
- output?: (_better_fetch_fetch0.StandardSchemaV1 | typeof Blob | typeof File) | undefined;
118
- errorSchema?: _better_fetch_fetch0.StandardSchemaV1 | undefined;
119
- disableValidation?: boolean | undefined;
120
- disableSignal?: boolean | undefined;
121
- }, unknown, unknown, {}>;
122
- $store: {
123
- notify: (signal?: (Omit<string, "$sessionSignal"> | "$sessionSignal") | undefined) => void;
124
- listen: (signal: Omit<string, "$sessionSignal"> | "$sessionSignal", listener: (value: boolean, oldValue?: boolean | undefined) => void) => void;
125
- atoms: Record<string, nanostores.WritableAtom<any>>;
35
+ Session: NonNullable<ClientSession<Option>>;
126
36
  };
37
+ $fetch: ClientConfig["$fetch"];
38
+ $store: ClientConfig["$store"];
127
39
  $ERROR_CODES: InferErrorCodes<Option> & typeof BASE_ERROR_CODES;
128
40
  };
41
+ declare function createAuthClient<Option extends BetterAuthClientOptions>(options?: Option | undefined): ReactAuthClient<Option>;
129
42
  //#endregion
130
- export { ExtractPluginField, HasRequiredKeys, InferPluginFieldFromTuple, IsAny, OverrideMerge, Prettify, PrettifyDeep, RequiredKeysOf, StripEmptyObjects, type UnionToIntersection, createAuthClient, useStore };
43
+ export { ExtractPluginField, HasRequiredKeys, InferPluginFieldFromTuple, IsAny, OverrideMerge, Prettify, PrettifyDeep, ReactAuthClient, RequiredKeysOf, StripEmptyObjects, type UnionToIntersection, createAuthClient, useStore };
@@ -1,9 +1,9 @@
1
1
  import { ExtractPluginField, HasRequiredKeys, InferPluginFieldFromTuple, IsAny, OverrideMerge, Prettify, PrettifyDeep, RequiredKeysOf, StripEmptyObjects, UnionToIntersection } from "../../types/helper.mjs";
2
2
  import { InferActions, InferClientAPI, InferErrorCodes, IsSignal, SessionQueryParams } from "../types.mjs";
3
+ import { getClientConfig } from "../config.mjs";
3
4
  import { BetterAuthClientOptions } from "@better-auth/core";
4
5
  import { BASE_ERROR_CODES } from "@better-auth/core/error";
5
- import * as _better_fetch_fetch0 from "@better-fetch/fetch";
6
- import { BetterFetchError } from "@better-fetch/fetch";
6
+ import { BetterFetchError, BetterFetchResponse } from "@better-fetch/fetch";
7
7
  import { Accessor } from "solid-js";
8
8
  export * from "nanostores";
9
9
  export * from "@better-fetch/fetch";
@@ -14,21 +14,16 @@ type InferResolvedHooks<O extends BetterAuthClientOptions> = O extends {
14
14
  } ? UnionToIntersection<Plugin extends {
15
15
  getAtoms?: infer GetAtoms;
16
16
  } ? GetAtoms extends ((fetch: any) => infer Atoms) ? Atoms extends Record<string, any> ? { [key in keyof Atoms as IsSignal<key> extends true ? never : key extends string ? `use${Capitalize<key>}` : never]: () => Accessor<ReturnType<Atoms[key]["get"]>> } : {} : {} : {}> : {};
17
- declare function createAuthClient<Option extends BetterAuthClientOptions>(options?: Option | undefined): UnionToIntersection<InferResolvedHooks<Option>> & InferClientAPI<Option> & InferActions<Option> & {
17
+ type ClientConfig = ReturnType<typeof getClientConfig>;
18
+ type ClientSession<Option extends BetterAuthClientOptions> = InferClientAPI<Option> extends {
19
+ getSession: () => Promise<infer Res>;
20
+ } ? Res extends BetterFetchResponse<infer S> ? S : Res extends Record<string, any> ? Res : never : never;
21
+ /**
22
+ * Solid client returned by `createAuthClient`.
23
+ */
24
+ type SolidAuthClient<Option extends BetterAuthClientOptions> = UnionToIntersection<InferResolvedHooks<Option>> & InferClientAPI<Option> & InferActions<Option> & {
18
25
  useSession: () => Accessor<{
19
- data: InferClientAPI<Option> extends {
20
- getSession: () => Promise<infer Res>;
21
- } ? Res extends {
22
- data: null;
23
- error: {
24
- message?: string | undefined;
25
- status: number;
26
- statusText: string;
27
- };
28
- } | {
29
- data: infer S;
30
- error: null;
31
- } ? S : Res extends Record<string, any> ? Res : never : never;
26
+ data: ClientSession<Option>;
32
27
  isPending: boolean;
33
28
  isRefetching: boolean;
34
29
  error: BetterFetchError | null;
@@ -37,88 +32,11 @@ declare function createAuthClient<Option extends BetterAuthClientOptions>(option
37
32
  } | undefined) => Promise<void>;
38
33
  }>;
39
34
  $Infer: {
40
- Session: NonNullable<InferClientAPI<Option> extends {
41
- getSession: () => Promise<infer Res>;
42
- } ? Res extends {
43
- data: null;
44
- error: {
45
- message?: string | undefined;
46
- status: number;
47
- statusText: string;
48
- };
49
- } | {
50
- data: infer S;
51
- error: null;
52
- } ? S : Res extends Record<string, any> ? Res : never : never>;
35
+ Session: NonNullable<ClientSession<Option>>;
53
36
  };
54
- $fetch: _better_fetch_fetch0.BetterFetch<{
55
- plugins: (_better_fetch_fetch0.BetterFetchPlugin<Record<string, any>> | {
56
- id: string;
57
- name: string;
58
- hooks: {
59
- onSuccess(context: _better_fetch_fetch0.SuccessContext<any>): void;
60
- };
61
- } | {
62
- id: string;
63
- name: string;
64
- hooks: {
65
- onSuccess: ((context: _better_fetch_fetch0.SuccessContext<any>) => Promise<void> | void) | undefined;
66
- onError: ((context: _better_fetch_fetch0.ErrorContext) => Promise<void> | void) | undefined;
67
- onRequest: (<T extends Record<string, any>>(context: _better_fetch_fetch0.RequestContext<T>) => Promise<_better_fetch_fetch0.RequestContext | void> | _better_fetch_fetch0.RequestContext | void) | undefined;
68
- onResponse: ((context: _better_fetch_fetch0.ResponseContext) => Promise<Response | void | _better_fetch_fetch0.ResponseContext> | Response | _better_fetch_fetch0.ResponseContext | void) | undefined;
69
- };
70
- })[];
71
- priority?: RequestPriority | undefined;
72
- cache?: RequestCache | undefined;
73
- credentials?: RequestCredentials;
74
- integrity?: string | undefined;
75
- keepalive?: boolean | undefined;
76
- method: string;
77
- mode?: RequestMode | undefined;
78
- redirect?: RequestRedirect | undefined;
79
- referrer?: string | undefined;
80
- referrerPolicy?: ReferrerPolicy | undefined;
81
- signal?: (AbortSignal | null) | undefined;
82
- window?: null | undefined;
83
- onRetry?: ((response: _better_fetch_fetch0.ResponseContext) => Promise<void> | void) | undefined;
84
- hookOptions?: {
85
- cloneResponse?: boolean;
86
- } | undefined;
87
- timeout?: number | undefined;
88
- customFetchImpl: _better_fetch_fetch0.FetchEsque;
89
- baseURL: string;
90
- throw?: boolean | undefined;
91
- auth?: ({
92
- type: "Bearer";
93
- token: string | Promise<string | undefined> | (() => string | Promise<string | undefined> | undefined) | undefined;
94
- } | {
95
- type: "Basic";
96
- username: string | (() => string | undefined) | undefined;
97
- password: string | (() => string | undefined) | undefined;
98
- } | {
99
- type: "Custom";
100
- prefix: string | (() => string | undefined) | undefined;
101
- value: string | (() => string | undefined) | undefined;
102
- }) | undefined;
103
- headers?: {} | {
104
- [x: string]: string | undefined;
105
- accept?: ((string & {}) | "application/json" | "text/plain" | "application/octet-stream") | undefined;
106
- "content-type"?: ((string & {}) | "application/x-www-form-urlencoded" | "application/json" | "text/plain" | "application/octet-stream" | "multipart/form-data") | undefined;
107
- authorization?: ((string & {}) | `Bearer ${string}` | `Basic ${string}`) | undefined;
108
- } | undefined;
109
- body?: any;
110
- query?: any;
111
- params?: any;
112
- duplex?: "full" | "half" | undefined;
113
- jsonParser: (text: string) => Promise<any> | any;
114
- retry?: _better_fetch_fetch0.RetryOptions | undefined;
115
- retryAttempt?: number | undefined;
116
- output?: (_better_fetch_fetch0.StandardSchemaV1 | typeof Blob | typeof File) | undefined;
117
- errorSchema?: _better_fetch_fetch0.StandardSchemaV1 | undefined;
118
- disableValidation?: boolean | undefined;
119
- disableSignal?: boolean | undefined;
120
- }, unknown, unknown, {}>;
37
+ $fetch: ClientConfig["$fetch"];
121
38
  $ERROR_CODES: PrettifyDeep<InferErrorCodes<Option> & typeof BASE_ERROR_CODES>;
122
39
  };
40
+ declare function createAuthClient<Option extends BetterAuthClientOptions>(options?: Option | undefined): SolidAuthClient<Option>;
123
41
  //#endregion
124
- export { ExtractPluginField, HasRequiredKeys, InferPluginFieldFromTuple, IsAny, OverrideMerge, Prettify, PrettifyDeep, RequiredKeysOf, StripEmptyObjects, type UnionToIntersection, createAuthClient };
42
+ export { ExtractPluginField, HasRequiredKeys, InferPluginFieldFromTuple, IsAny, OverrideMerge, Prettify, PrettifyDeep, RequiredKeysOf, SolidAuthClient, StripEmptyObjects, type UnionToIntersection, createAuthClient };