better-auth 1.6.17 → 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,33 +1,29 @@
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
- import { BetterAuthClientOptions, BetterAuthClientPlugin } from "@better-auth/core";
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
 
12
11
  //#region src/client/lynx/index.d.ts
13
12
  type InferResolvedHooks<O extends BetterAuthClientOptions> = O extends {
14
13
  plugins: Array<infer Plugin>;
15
- } ? UnionToIntersection<Plugin extends BetterAuthClientPlugin ? Plugin["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"]> } : {} : {} : {}> : {};
16
- declare function createAuthClient<Option extends BetterAuthClientOptions>(options?: Option | undefined): UnionToIntersection<InferResolvedHooks<Option>> & InferClientAPI<Option> & InferActions<Option> & {
14
+ } ? UnionToIntersection<Plugin extends {
15
+ getAtoms?: infer GetAtoms;
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"]> } : {} : {} : {}> : {};
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> & {
17
25
  useSession: () => {
18
- data: InferClientAPI<Option> extends {
19
- getSession: () => Promise<infer Res>;
20
- } ? Res extends {
21
- data: null;
22
- error: {
23
- message?: string | undefined;
24
- status: number;
25
- statusText: string;
26
- };
27
- } | {
28
- data: infer S;
29
- error: null;
30
- } ? S : Res : never;
26
+ data: ClientSession<Option>;
31
27
  isPending: boolean;
32
28
  error: BetterFetchError | null;
33
29
  refetch: (queryParams?: {
@@ -35,93 +31,12 @@ declare function createAuthClient<Option extends BetterAuthClientOptions>(option
35
31
  } | undefined) => Promise<void>;
36
32
  };
37
33
  $Infer: {
38
- Session: NonNullable<InferClientAPI<Option> extends {
39
- getSession: () => Promise<infer Res>;
40
- } ? Res extends {
41
- data: null;
42
- error: {
43
- message?: string | undefined;
44
- status: number;
45
- statusText: string;
46
- };
47
- } | {
48
- data: infer S;
49
- error: null;
50
- } ? S : Res : never>;
51
- };
52
- $fetch: _better_fetch_fetch0.BetterFetch<{
53
- plugins: (_better_fetch_fetch0.BetterFetchPlugin<Record<string, any>> | {
54
- id: string;
55
- name: string;
56
- hooks: {
57
- onSuccess(context: _better_fetch_fetch0.SuccessContext<any>): void;
58
- };
59
- } | {
60
- id: string;
61
- name: string;
62
- hooks: {
63
- onSuccess: ((context: _better_fetch_fetch0.SuccessContext<any>) => Promise<void> | void) | undefined;
64
- onError: ((context: _better_fetch_fetch0.ErrorContext) => Promise<void> | void) | undefined;
65
- onRequest: (<T extends Record<string, any>>(context: _better_fetch_fetch0.RequestContext<T>) => Promise<_better_fetch_fetch0.RequestContext | void> | _better_fetch_fetch0.RequestContext | void) | undefined;
66
- onResponse: ((context: _better_fetch_fetch0.ResponseContext) => Promise<Response | void | _better_fetch_fetch0.ResponseContext> | Response | _better_fetch_fetch0.ResponseContext | void) | undefined;
67
- };
68
- })[];
69
- priority?: RequestPriority | undefined;
70
- cache?: RequestCache | undefined;
71
- credentials?: RequestCredentials;
72
- integrity?: string | undefined;
73
- keepalive?: boolean | undefined;
74
- method: string;
75
- mode?: RequestMode | undefined;
76
- redirect?: RequestRedirect | undefined;
77
- referrer?: string | undefined;
78
- referrerPolicy?: ReferrerPolicy | undefined;
79
- signal?: (AbortSignal | null) | undefined;
80
- window?: null | undefined;
81
- onRetry?: ((response: _better_fetch_fetch0.ResponseContext) => Promise<void> | void) | undefined;
82
- hookOptions?: {
83
- cloneResponse?: boolean;
84
- } | undefined;
85
- timeout?: number | undefined;
86
- customFetchImpl: _better_fetch_fetch0.FetchEsque;
87
- baseURL: string;
88
- throw?: boolean | undefined;
89
- auth?: ({
90
- type: "Bearer";
91
- token: string | Promise<string | undefined> | (() => string | Promise<string | undefined> | undefined) | undefined;
92
- } | {
93
- type: "Basic";
94
- username: string | (() => string | undefined) | undefined;
95
- password: string | (() => string | undefined) | undefined;
96
- } | {
97
- type: "Custom";
98
- prefix: string | (() => string | undefined) | undefined;
99
- value: string | (() => string | undefined) | undefined;
100
- }) | undefined;
101
- headers?: {} | {
102
- [x: string]: string | undefined;
103
- accept?: ((string & {}) | "application/json" | "text/plain" | "application/octet-stream") | undefined;
104
- "content-type"?: ((string & {}) | "application/x-www-form-urlencoded" | "application/json" | "text/plain" | "application/octet-stream" | "multipart/form-data") | undefined;
105
- authorization?: ((string & {}) | `Bearer ${string}` | `Basic ${string}`) | undefined;
106
- } | undefined;
107
- body?: any;
108
- query?: any;
109
- params?: any;
110
- duplex?: "full" | "half" | undefined;
111
- jsonParser: (text: string) => Promise<any> | any;
112
- retry?: _better_fetch_fetch0.RetryOptions | undefined;
113
- retryAttempt?: number | undefined;
114
- output?: (_better_fetch_fetch0.StandardSchemaV1 | typeof Blob | typeof File) | undefined;
115
- errorSchema?: _better_fetch_fetch0.StandardSchemaV1 | undefined;
116
- disableValidation?: boolean | undefined;
117
- disableSignal?: boolean | undefined;
118
- }, unknown, unknown, {}>;
119
- $store: {
120
- notify: (signal?: (Omit<string, "$sessionSignal"> | "$sessionSignal") | undefined) => void;
121
- listen: (signal: Omit<string, "$sessionSignal"> | "$sessionSignal", listener: (value: boolean, oldValue?: boolean | undefined) => void) => void;
122
- atoms: Record<string, nanostores.WritableAtom<any>>;
34
+ Session: NonNullable<ClientSession<Option>>;
123
35
  };
36
+ $fetch: ClientConfig["$fetch"];
37
+ $store: ClientConfig["$store"];
124
38
  $ERROR_CODES: PrettifyDeep<InferErrorCodes<Option> & typeof BASE_ERROR_CODES>;
125
39
  };
40
+ declare function createAuthClient<Option extends BetterAuthClientOptions>(options?: Option | undefined): LynxAuthClient<Option>;
126
41
  //#endregion
127
- 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,33 +1,29 @@
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
- import { BetterAuthClientOptions, BetterAuthClientPlugin } from "@better-auth/core";
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
 
12
11
  //#region src/client/react/index.d.ts
13
12
  type InferResolvedHooks<O extends BetterAuthClientOptions> = O extends {
14
13
  plugins: Array<infer Plugin>;
15
- } ? UnionToIntersection<Plugin extends BetterAuthClientPlugin ? Plugin["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"]> } : {} : {} : {}> : {};
16
- declare function createAuthClient<Option extends BetterAuthClientOptions>(options?: Option | undefined): UnionToIntersection<InferResolvedHooks<Option>> & InferClientAPI<Option> & InferActions<Option> & {
14
+ } ? UnionToIntersection<Plugin extends {
15
+ getAtoms?: infer GetAtoms;
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"]> } : {} : {} : {}> : {};
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> & {
17
25
  useSession: () => {
18
- data: InferClientAPI<Option> extends {
19
- getSession: () => Promise<infer Res>;
20
- } ? Res extends {
21
- data: null;
22
- error: {
23
- message?: string | undefined;
24
- status: number;
25
- statusText: string;
26
- };
27
- } | {
28
- data: infer S;
29
- error: null;
30
- } ? S : Res : never;
26
+ data: ClientSession<Option>;
31
27
  isPending: boolean;
32
28
  isRefetching: boolean;
33
29
  error: BetterFetchError | null;
@@ -36,93 +32,12 @@ declare function createAuthClient<Option extends BetterAuthClientOptions>(option
36
32
  } | undefined) => Promise<void>;
37
33
  };
38
34
  $Infer: {
39
- Session: NonNullable<InferClientAPI<Option> extends {
40
- getSession: () => Promise<infer Res>;
41
- } ? Res extends {
42
- data: null;
43
- error: {
44
- message?: string | undefined;
45
- status: number;
46
- statusText: string;
47
- };
48
- } | {
49
- data: infer S;
50
- error: null;
51
- } ? S : Res : never>;
52
- };
53
- $fetch: _better_fetch_fetch0.BetterFetch<{
54
- plugins: (_better_fetch_fetch0.BetterFetchPlugin<Record<string, any>> | {
55
- id: string;
56
- name: string;
57
- hooks: {
58
- onSuccess(context: _better_fetch_fetch0.SuccessContext<any>): void;
59
- };
60
- } | {
61
- id: string;
62
- name: string;
63
- hooks: {
64
- onSuccess: ((context: _better_fetch_fetch0.SuccessContext<any>) => Promise<void> | void) | undefined;
65
- onError: ((context: _better_fetch_fetch0.ErrorContext) => Promise<void> | void) | undefined;
66
- onRequest: (<T extends Record<string, any>>(context: _better_fetch_fetch0.RequestContext<T>) => Promise<_better_fetch_fetch0.RequestContext | void> | _better_fetch_fetch0.RequestContext | void) | undefined;
67
- onResponse: ((context: _better_fetch_fetch0.ResponseContext) => Promise<Response | void | _better_fetch_fetch0.ResponseContext> | Response | _better_fetch_fetch0.ResponseContext | void) | undefined;
68
- };
69
- })[];
70
- priority?: RequestPriority | undefined;
71
- cache?: RequestCache | undefined;
72
- credentials?: RequestCredentials;
73
- integrity?: string | undefined;
74
- keepalive?: boolean | undefined;
75
- method: string;
76
- mode?: RequestMode | undefined;
77
- redirect?: RequestRedirect | undefined;
78
- referrer?: string | undefined;
79
- referrerPolicy?: ReferrerPolicy | undefined;
80
- signal?: (AbortSignal | null) | undefined;
81
- window?: null | undefined;
82
- onRetry?: ((response: _better_fetch_fetch0.ResponseContext) => Promise<void> | void) | undefined;
83
- hookOptions?: {
84
- cloneResponse?: boolean;
85
- } | undefined;
86
- timeout?: number | undefined;
87
- customFetchImpl: _better_fetch_fetch0.FetchEsque;
88
- baseURL: string;
89
- throw?: boolean | undefined;
90
- auth?: ({
91
- type: "Bearer";
92
- token: string | Promise<string | undefined> | (() => string | Promise<string | undefined> | undefined) | undefined;
93
- } | {
94
- type: "Basic";
95
- username: string | (() => string | undefined) | undefined;
96
- password: string | (() => string | undefined) | undefined;
97
- } | {
98
- type: "Custom";
99
- prefix: string | (() => string | undefined) | undefined;
100
- value: string | (() => string | undefined) | undefined;
101
- }) | undefined;
102
- headers?: {} | {
103
- [x: string]: string | undefined;
104
- accept?: ((string & {}) | "application/json" | "text/plain" | "application/octet-stream") | undefined;
105
- "content-type"?: ((string & {}) | "application/x-www-form-urlencoded" | "application/json" | "text/plain" | "application/octet-stream" | "multipart/form-data") | undefined;
106
- authorization?: ((string & {}) | `Bearer ${string}` | `Basic ${string}`) | undefined;
107
- } | undefined;
108
- body?: any;
109
- query?: any;
110
- params?: any;
111
- duplex?: "full" | "half" | undefined;
112
- jsonParser: (text: string) => Promise<any> | any;
113
- retry?: _better_fetch_fetch0.RetryOptions | undefined;
114
- retryAttempt?: number | undefined;
115
- output?: (_better_fetch_fetch0.StandardSchemaV1 | typeof Blob | typeof File) | undefined;
116
- errorSchema?: _better_fetch_fetch0.StandardSchemaV1 | undefined;
117
- disableValidation?: boolean | undefined;
118
- disableSignal?: boolean | undefined;
119
- }, unknown, unknown, {}>;
120
- $store: {
121
- notify: (signal?: (Omit<string, "$sessionSignal"> | "$sessionSignal") | undefined) => void;
122
- listen: (signal: Omit<string, "$sessionSignal"> | "$sessionSignal", listener: (value: boolean, oldValue?: boolean | undefined) => void) => void;
123
- atoms: Record<string, nanostores.WritableAtom<any>>;
35
+ Session: NonNullable<ClientSession<Option>>;
124
36
  };
37
+ $fetch: ClientConfig["$fetch"];
38
+ $store: ClientConfig["$store"];
125
39
  $ERROR_CODES: InferErrorCodes<Option> & typeof BASE_ERROR_CODES;
126
40
  };
41
+ declare function createAuthClient<Option extends BetterAuthClientOptions>(options?: Option | undefined): ReactAuthClient<Option>;
127
42
  //#endregion
128
- 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 { BetterAuthClientOptions, BetterAuthClientPlugin } from "@better-auth/core";
3
+ import { getClientConfig } from "../config.mjs";
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";
@@ -11,22 +11,19 @@ export * from "@better-fetch/fetch";
11
11
  //#region src/client/solid/index.d.ts
12
12
  type InferResolvedHooks<O extends BetterAuthClientOptions> = O extends {
13
13
  plugins: Array<infer Plugin>;
14
- } ? UnionToIntersection<Plugin extends BetterAuthClientPlugin ? Plugin["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"]>> } : {} : {} : {}> : {};
15
- declare function createAuthClient<Option extends BetterAuthClientOptions>(options?: Option | undefined): UnionToIntersection<InferResolvedHooks<Option>> & InferClientAPI<Option> & InferActions<Option> & {
14
+ } ? UnionToIntersection<Plugin extends {
15
+ getAtoms?: infer GetAtoms;
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
+ 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> & {
16
25
  useSession: () => Accessor<{
17
- data: InferClientAPI<Option> extends {
18
- getSession: () => Promise<infer Res>;
19
- } ? Res extends {
20
- data: null;
21
- error: {
22
- message?: string | undefined;
23
- status: number;
24
- statusText: string;
25
- };
26
- } | {
27
- data: infer S;
28
- error: null;
29
- } ? S : Res extends Record<string, any> ? Res : never : never;
26
+ data: ClientSession<Option>;
30
27
  isPending: boolean;
31
28
  isRefetching: boolean;
32
29
  error: BetterFetchError | null;
@@ -35,88 +32,11 @@ declare function createAuthClient<Option extends BetterAuthClientOptions>(option
35
32
  } | undefined) => Promise<void>;
36
33
  }>;
37
34
  $Infer: {
38
- Session: NonNullable<InferClientAPI<Option> extends {
39
- getSession: () => Promise<infer Res>;
40
- } ? Res extends {
41
- data: null;
42
- error: {
43
- message?: string | undefined;
44
- status: number;
45
- statusText: string;
46
- };
47
- } | {
48
- data: infer S;
49
- error: null;
50
- } ? S : Res extends Record<string, any> ? Res : never : never>;
35
+ Session: NonNullable<ClientSession<Option>>;
51
36
  };
52
- $fetch: _better_fetch_fetch0.BetterFetch<{
53
- plugins: (_better_fetch_fetch0.BetterFetchPlugin<Record<string, any>> | {
54
- id: string;
55
- name: string;
56
- hooks: {
57
- onSuccess(context: _better_fetch_fetch0.SuccessContext<any>): void;
58
- };
59
- } | {
60
- id: string;
61
- name: string;
62
- hooks: {
63
- onSuccess: ((context: _better_fetch_fetch0.SuccessContext<any>) => Promise<void> | void) | undefined;
64
- onError: ((context: _better_fetch_fetch0.ErrorContext) => Promise<void> | void) | undefined;
65
- onRequest: (<T extends Record<string, any>>(context: _better_fetch_fetch0.RequestContext<T>) => Promise<_better_fetch_fetch0.RequestContext | void> | _better_fetch_fetch0.RequestContext | void) | undefined;
66
- onResponse: ((context: _better_fetch_fetch0.ResponseContext) => Promise<Response | void | _better_fetch_fetch0.ResponseContext> | Response | _better_fetch_fetch0.ResponseContext | void) | undefined;
67
- };
68
- })[];
69
- priority?: RequestPriority | undefined;
70
- cache?: RequestCache | undefined;
71
- credentials?: RequestCredentials;
72
- integrity?: string | undefined;
73
- keepalive?: boolean | undefined;
74
- method: string;
75
- mode?: RequestMode | undefined;
76
- redirect?: RequestRedirect | undefined;
77
- referrer?: string | undefined;
78
- referrerPolicy?: ReferrerPolicy | undefined;
79
- signal?: (AbortSignal | null) | undefined;
80
- window?: null | undefined;
81
- onRetry?: ((response: _better_fetch_fetch0.ResponseContext) => Promise<void> | void) | undefined;
82
- hookOptions?: {
83
- cloneResponse?: boolean;
84
- } | undefined;
85
- timeout?: number | undefined;
86
- customFetchImpl: _better_fetch_fetch0.FetchEsque;
87
- baseURL: string;
88
- throw?: boolean | undefined;
89
- auth?: ({
90
- type: "Bearer";
91
- token: string | Promise<string | undefined> | (() => string | Promise<string | undefined> | undefined) | undefined;
92
- } | {
93
- type: "Basic";
94
- username: string | (() => string | undefined) | undefined;
95
- password: string | (() => string | undefined) | undefined;
96
- } | {
97
- type: "Custom";
98
- prefix: string | (() => string | undefined) | undefined;
99
- value: string | (() => string | undefined) | undefined;
100
- }) | undefined;
101
- headers?: {} | {
102
- [x: string]: string | undefined;
103
- accept?: ((string & {}) | "application/json" | "text/plain" | "application/octet-stream") | undefined;
104
- "content-type"?: ((string & {}) | "application/x-www-form-urlencoded" | "application/json" | "text/plain" | "application/octet-stream" | "multipart/form-data") | undefined;
105
- authorization?: ((string & {}) | `Bearer ${string}` | `Basic ${string}`) | undefined;
106
- } | undefined;
107
- body?: any;
108
- query?: any;
109
- params?: any;
110
- duplex?: "full" | "half" | undefined;
111
- jsonParser: (text: string) => Promise<any> | any;
112
- retry?: _better_fetch_fetch0.RetryOptions | undefined;
113
- retryAttempt?: number | undefined;
114
- output?: (_better_fetch_fetch0.StandardSchemaV1 | typeof Blob | typeof File) | undefined;
115
- errorSchema?: _better_fetch_fetch0.StandardSchemaV1 | undefined;
116
- disableValidation?: boolean | undefined;
117
- disableSignal?: boolean | undefined;
118
- }, unknown, unknown, {}>;
37
+ $fetch: ClientConfig["$fetch"];
119
38
  $ERROR_CODES: PrettifyDeep<InferErrorCodes<Option> & typeof BASE_ERROR_CODES>;
120
39
  };
40
+ declare function createAuthClient<Option extends BetterAuthClientOptions>(options?: Option | undefined): SolidAuthClient<Option>;
121
41
  //#endregion
122
- 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 };