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.
@@ -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 { 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 nanostores from "nanostores";
6
6
  import { Atom } 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/svelte/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]: () => Atoms[key] } : {} : {} : {}> : {};
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]: () => Atoms[key] } : {} : {} : {}> : {};
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
+ * Svelte client returned by `createAuthClient`.
23
+ */
24
+ type SvelteAuthClient<Option extends BetterAuthClientOptions> = UnionToIntersection<InferResolvedHooks<Option>> & InferClientAPI<Option> & InferActions<Option> & {
17
25
  useSession: () => Atom<{
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 extends Record<string, any> ? Res : never : never;
26
+ data: ClientSession<Option>;
31
27
  error: BetterFetchError | null;
32
28
  isPending: boolean;
33
29
  isRefetching: boolean;
@@ -35,94 +31,13 @@ declare function createAuthClient<Option extends BetterAuthClientOptions>(option
35
31
  query?: SessionQueryParams;
36
32
  } | undefined) => Promise<void>;
37
33
  }>;
38
- $fetch: _better_fetch_fetch0.BetterFetch<{
39
- plugins: (_better_fetch_fetch0.BetterFetchPlugin<Record<string, any>> | {
40
- id: string;
41
- name: string;
42
- hooks: {
43
- onSuccess(context: _better_fetch_fetch0.SuccessContext<any>): void;
44
- };
45
- } | {
46
- id: string;
47
- name: string;
48
- hooks: {
49
- onSuccess: ((context: _better_fetch_fetch0.SuccessContext<any>) => Promise<void> | void) | undefined;
50
- onError: ((context: _better_fetch_fetch0.ErrorContext) => Promise<void> | void) | undefined;
51
- onRequest: (<T extends Record<string, any>>(context: _better_fetch_fetch0.RequestContext<T>) => Promise<_better_fetch_fetch0.RequestContext | void> | _better_fetch_fetch0.RequestContext | void) | undefined;
52
- onResponse: ((context: _better_fetch_fetch0.ResponseContext) => Promise<Response | void | _better_fetch_fetch0.ResponseContext> | Response | _better_fetch_fetch0.ResponseContext | void) | undefined;
53
- };
54
- })[];
55
- priority?: RequestPriority | undefined;
56
- cache?: RequestCache | undefined;
57
- credentials?: RequestCredentials;
58
- integrity?: string | undefined;
59
- keepalive?: boolean | undefined;
60
- method: string;
61
- mode?: RequestMode | undefined;
62
- redirect?: RequestRedirect | undefined;
63
- referrer?: string | undefined;
64
- referrerPolicy?: ReferrerPolicy | undefined;
65
- signal?: (AbortSignal | null) | undefined;
66
- window?: null | undefined;
67
- onRetry?: ((response: _better_fetch_fetch0.ResponseContext) => Promise<void> | void) | undefined;
68
- hookOptions?: {
69
- cloneResponse?: boolean;
70
- } | undefined;
71
- timeout?: number | undefined;
72
- customFetchImpl: _better_fetch_fetch0.FetchEsque;
73
- baseURL: string;
74
- throw?: boolean | undefined;
75
- auth?: ({
76
- type: "Bearer";
77
- token: string | Promise<string | undefined> | (() => string | Promise<string | undefined> | undefined) | undefined;
78
- } | {
79
- type: "Basic";
80
- username: string | (() => string | undefined) | undefined;
81
- password: string | (() => string | undefined) | undefined;
82
- } | {
83
- type: "Custom";
84
- prefix: string | (() => string | undefined) | undefined;
85
- value: string | (() => string | undefined) | undefined;
86
- }) | undefined;
87
- headers?: {} | {
88
- [x: string]: string | undefined;
89
- accept?: ((string & {}) | "application/json" | "text/plain" | "application/octet-stream") | undefined;
90
- "content-type"?: ((string & {}) | "application/x-www-form-urlencoded" | "application/json" | "text/plain" | "application/octet-stream" | "multipart/form-data") | undefined;
91
- authorization?: ((string & {}) | `Bearer ${string}` | `Basic ${string}`) | undefined;
92
- } | undefined;
93
- body?: any;
94
- query?: any;
95
- params?: any;
96
- duplex?: "full" | "half" | undefined;
97
- jsonParser: (text: string) => Promise<any> | any;
98
- retry?: _better_fetch_fetch0.RetryOptions | undefined;
99
- retryAttempt?: number | undefined;
100
- output?: (_better_fetch_fetch0.StandardSchemaV1 | typeof Blob | typeof File) | undefined;
101
- errorSchema?: _better_fetch_fetch0.StandardSchemaV1 | undefined;
102
- disableValidation?: boolean | undefined;
103
- disableSignal?: boolean | undefined;
104
- }, unknown, unknown, {}>;
105
- $store: {
106
- notify: (signal?: (Omit<string, "$sessionSignal"> | "$sessionSignal") | undefined) => void;
107
- listen: (signal: Omit<string, "$sessionSignal"> | "$sessionSignal", listener: (value: boolean, oldValue?: boolean | undefined) => void) => void;
108
- atoms: Record<string, nanostores.WritableAtom<any>>;
109
- };
34
+ $fetch: ClientConfig["$fetch"];
35
+ $store: ClientConfig["$store"];
110
36
  $Infer: {
111
- Session: NonNullable<InferClientAPI<Option> extends {
112
- getSession: () => Promise<infer Res>;
113
- } ? Res extends {
114
- data: null;
115
- error: {
116
- message?: string | undefined;
117
- status: number;
118
- statusText: string;
119
- };
120
- } | {
121
- data: infer S;
122
- error: null;
123
- } ? S : Res extends Record<string, any> ? Res : never : never>;
37
+ Session: NonNullable<ClientSession<Option>>;
124
38
  };
125
39
  $ERROR_CODES: PrettifyDeep<InferErrorCodes<Option> & typeof BASE_ERROR_CODES>;
126
40
  };
41
+ declare function createAuthClient<Option extends BetterAuthClientOptions>(options?: Option | undefined): SvelteAuthClient<Option>;
127
42
  //#endregion
128
- export { ExtractPluginField, HasRequiredKeys, InferPluginFieldFromTuple, IsAny, OverrideMerge, Prettify, PrettifyDeep, RequiredKeysOf, StripEmptyObjects, type UnionToIntersection, createAuthClient };
43
+ export { ExtractPluginField, HasRequiredKeys, InferPluginFieldFromTuple, IsAny, OverrideMerge, Prettify, PrettifyDeep, RequiredKeysOf, StripEmptyObjects, SvelteAuthClient, type UnionToIntersection, createAuthClient };
@@ -3,25 +3,32 @@ import { StripEmptyObjects, UnionToIntersection } from "../types/helper.mjs";
3
3
  import { InferRoutes } from "./path-to-object.mjs";
4
4
  import { Session as Session$1, User as User$1 } from "../types/models.mjs";
5
5
  import { Auth } from "../types/auth.mjs";
6
- import { BetterAuthClientOptions as BetterAuthClientOptions$1, BetterAuthClientPlugin as BetterAuthClientPlugin$1, ClientAtomListener, ClientStore as ClientStore$1 } from "@better-auth/core";
7
- import { BetterAuthPluginDBSchema, InferDBFieldsOutput } from "@better-auth/core/db";
8
- import { RawError } from "@better-auth/core/utils/error-codes";
6
+ import { BetterAuthClientOptions as BetterAuthClientOptions$1, BetterAuthClientPlugin, ClientAtomListener as ClientAtomListener$1, ClientStore as ClientStore$1 } from "@better-auth/core";
7
+ import { DBFieldAttribute, InferDBFieldsOutput } from "@better-auth/core/db";
9
8
 
10
9
  //#region src/client/types.d.ts
10
+ type ClientPluginError<K extends string = string> = {
11
+ readonly code: K;
12
+ message: string;
13
+ };
11
14
  type InferPluginEndpoints<Plugins> = Plugins extends Array<infer Pl> ? UnionToIntersection<Pl extends {
12
- $InferServerPlugin: infer Plug;
15
+ $InferServerPlugin?: infer Plug;
13
16
  } ? Plug extends {
14
- endpoints: infer Endpoints;
15
- } ? Endpoints : {} : {}> : {};
17
+ endpoints?: infer Endpoints;
18
+ } ? Endpoints extends Record<string, unknown> ? Endpoints : {} : {} : {}> : {};
16
19
  type InferClientAPI<O extends BetterAuthClientOptions$1> = InferRoutes<O["plugins"] extends Array<any> ? Omit<Auth["api"], keyof InferPluginEndpoints<O["plugins"]>> & InferPluginEndpoints<O["plugins"]> : Auth["api"], O>;
17
- type InferActions<O extends BetterAuthClientOptions$1> = (O["plugins"] extends Array<infer Plugin> ? UnionToIntersection<Plugin extends BetterAuthClientPlugin$1 ? Plugin["getActions"] extends ((...args: any) => infer Actions) ? Actions : {} : {}> : {}) & InferRoutes<O["$InferAuth"] extends {
20
+ type InferActions<O extends BetterAuthClientOptions$1> = (O["plugins"] extends Array<infer Plugin> ? UnionToIntersection<Plugin extends {
21
+ getActions?: infer GetActions;
22
+ } ? GetActions extends ((...args: any) => infer Actions) ? Actions : {} : {}> : {}) & InferRoutes<O["$InferAuth"] extends {
18
23
  plugins: infer Plugins;
19
24
  } ? Plugins extends Array<infer Plugin> ? Plugin extends {
20
- endpoints: infer Endpoints;
21
- } ? Endpoints : {} : {} : {}, O>;
22
- type InferErrorCodes<O extends BetterAuthClientOptions$1> = O["plugins"] extends Array<infer Plugin> ? UnionToIntersection<Plugin extends BetterAuthClientPlugin$1 ? Plugin["$InferServerPlugin"] extends {
23
- $ERROR_CODES: infer E;
24
- } ? { [K in keyof E & string]: E[K] extends RawError ? RawError<K> : never } : {} : {}> : {};
25
+ endpoints?: infer Endpoints;
26
+ } ? Endpoints extends Record<string, unknown> ? Endpoints : {} : {} : {} : {}, O>;
27
+ type InferErrorCodes<O extends BetterAuthClientOptions$1> = O["plugins"] extends Array<infer Plugin> ? UnionToIntersection<Plugin extends {
28
+ $InferServerPlugin?: infer ServerPlugin;
29
+ } ? ServerPlugin extends {
30
+ $ERROR_CODES?: infer E;
31
+ } ? { [K in keyof E & string]: E[K] extends ClientPluginError ? ClientPluginError<K> : never } : {} : {}> : {};
25
32
  /**
26
33
  * signals are just used to recall a computed value.
27
34
  * as a convention they start with "$"
@@ -29,12 +36,16 @@ type InferErrorCodes<O extends BetterAuthClientOptions$1> = O["plugins"] extends
29
36
  type IsSignal<T> = T extends `$${infer _}` ? true : false;
30
37
  type InferSessionFromClient<O extends BetterAuthClientOptions$1> = StripEmptyObjects<Session$1 & UnionToIntersection<InferAdditionalFromClient<O, "session", "output">>>;
31
38
  type InferUserFromClient<O extends BetterAuthClientOptions$1> = StripEmptyObjects<User$1 & UnionToIntersection<InferAdditionalFromClient<O, "user", "output">>>;
32
- type InferAdditionalFromClient<Options extends BetterAuthClientOptions$1, Key extends string, Format extends "input" | "output" = "output"> = Options["plugins"] extends Array<infer Plugin> ? Plugin extends BetterAuthClientPlugin$1 ? Plugin["$InferServerPlugin"] extends {
33
- schema: infer Schema;
34
- } ? Schema extends BetterAuthPluginDBSchema ? Format extends "input" ? InferFieldsInputClient<Schema[Key]["fields"]> : InferDBFieldsOutput<Schema[Key]["fields"]> : {} : {} : {} : {};
39
+ type InferAdditionalFromClient<Options extends BetterAuthClientOptions$1, Key extends string, Format extends "input" | "output" = "output"> = Options["plugins"] extends Array<infer Plugin> ? Plugin extends {
40
+ $InferServerPlugin?: infer ServerPlugin;
41
+ } ? ServerPlugin extends {
42
+ schema?: infer Schema;
43
+ } ? Schema extends Record<Key, {
44
+ fields: infer Fields;
45
+ }> ? Fields extends Record<string, DBFieldAttribute> ? Format extends "input" ? InferFieldsInputClient<Fields> : InferDBFieldsOutput<Fields> : {} : {} : {} : {} : {};
35
46
  type SessionQueryParams = {
36
47
  disableCookieCache?: boolean | undefined;
37
48
  disableRefresh?: boolean | undefined;
38
49
  };
39
50
  //#endregion
40
- export { type BetterAuthClientOptions$1 as BetterAuthClientOptions, type BetterAuthClientPlugin$1 as BetterAuthClientPlugin, type ClientAtomListener, type ClientStore$1 as ClientStore, InferActions, InferAdditionalFromClient, InferClientAPI, InferErrorCodes, InferSessionFromClient, InferUserFromClient, IsSignal, SessionQueryParams };
51
+ export { type BetterAuthClientOptions$1 as BetterAuthClientOptions, type BetterAuthClientPlugin, type ClientAtomListener$1 as ClientAtomListener, type ClientStore$1 as ClientStore, InferActions, InferAdditionalFromClient, InferClientAPI, InferErrorCodes, InferSessionFromClient, InferUserFromClient, IsSignal, SessionQueryParams };
@@ -1,31 +1,27 @@
1
1
  import { PrettifyDeep, 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 nanostores from "nanostores";
6
6
  import { Atom } 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
 
10
9
  //#region src/client/vanilla.d.ts
11
10
  type InferResolvedHooks<O extends BetterAuthClientOptions> = O extends {
12
11
  plugins: Array<infer Plugin>;
13
- } ? 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]: Atoms[key] } : {} : {} : {}> : {};
14
- declare function createAuthClient<Option extends BetterAuthClientOptions>(options?: Option | undefined): UnionToIntersection<InferResolvedHooks<Option>> & InferClientAPI<Option> & InferActions<Option> & {
12
+ } ? UnionToIntersection<Plugin extends {
13
+ getAtoms?: infer GetAtoms;
14
+ } ? 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]: Atoms[key] } : {} : {} : {}> : {};
15
+ type ClientConfig = ReturnType<typeof getClientConfig>;
16
+ type ClientSession<Option extends BetterAuthClientOptions> = InferClientAPI<Option> extends {
17
+ getSession: () => Promise<infer Res>;
18
+ } ? Res extends BetterFetchResponse<infer S> ? S : Res extends Record<string, any> ? Res : never : never;
19
+ /**
20
+ * Client returned by `createAuthClient`.
21
+ */
22
+ type AuthClient<Option extends BetterAuthClientOptions> = UnionToIntersection<InferResolvedHooks<Option>> & InferClientAPI<Option> & InferActions<Option> & {
15
23
  useSession: Atom<{
16
- data: InferClientAPI<Option> extends {
17
- getSession: () => Promise<infer Res>;
18
- } ? Res extends {
19
- data: null;
20
- error: {
21
- message?: string | undefined;
22
- status: number;
23
- statusText: string;
24
- };
25
- } | {
26
- data: infer S;
27
- error: null;
28
- } ? S : Res extends Record<string, any> ? Res : never : never;
24
+ data: ClientSession<Option>;
29
25
  error: BetterFetchError | null;
30
26
  isPending: boolean;
31
27
  isRefetching: boolean;
@@ -33,95 +29,13 @@ declare function createAuthClient<Option extends BetterAuthClientOptions>(option
33
29
  query?: SessionQueryParams;
34
30
  } | undefined) => Promise<void>;
35
31
  }>;
36
- $fetch: _better_fetch_fetch0.BetterFetch<{
37
- plugins: (_better_fetch_fetch0.BetterFetchPlugin<Record<string, any>> | {
38
- id: string;
39
- name: string;
40
- hooks: {
41
- onSuccess(context: _better_fetch_fetch0.SuccessContext<any>): void;
42
- };
43
- } | {
44
- id: string;
45
- name: string;
46
- hooks: {
47
- onSuccess: ((context: _better_fetch_fetch0.SuccessContext<any>) => Promise<void> | void) | undefined;
48
- onError: ((context: _better_fetch_fetch0.ErrorContext) => Promise<void> | void) | undefined;
49
- onRequest: (<T extends Record<string, any>>(context: _better_fetch_fetch0.RequestContext<T>) => Promise<_better_fetch_fetch0.RequestContext | void> | _better_fetch_fetch0.RequestContext | void) | undefined;
50
- onResponse: ((context: _better_fetch_fetch0.ResponseContext) => Promise<Response | void | _better_fetch_fetch0.ResponseContext> | Response | _better_fetch_fetch0.ResponseContext | void) | undefined;
51
- };
52
- })[];
53
- priority?: RequestPriority | undefined;
54
- cache?: RequestCache | undefined;
55
- credentials?: RequestCredentials;
56
- integrity?: string | undefined;
57
- keepalive?: boolean | undefined;
58
- method: string;
59
- mode?: RequestMode | undefined;
60
- redirect?: RequestRedirect | undefined;
61
- referrer?: string | undefined;
62
- referrerPolicy?: ReferrerPolicy | undefined;
63
- signal?: (AbortSignal | null) | undefined;
64
- window?: null | undefined;
65
- onRetry?: ((response: _better_fetch_fetch0.ResponseContext) => Promise<void> | void) | undefined;
66
- hookOptions?: {
67
- cloneResponse?: boolean;
68
- } | undefined;
69
- timeout?: number | undefined;
70
- customFetchImpl: _better_fetch_fetch0.FetchEsque;
71
- baseURL: string;
72
- throw?: boolean | undefined;
73
- auth?: ({
74
- type: "Bearer";
75
- token: string | Promise<string | undefined> | (() => string | Promise<string | undefined> | undefined) | undefined;
76
- } | {
77
- type: "Basic";
78
- username: string | (() => string | undefined) | undefined;
79
- password: string | (() => string | undefined) | undefined;
80
- } | {
81
- type: "Custom";
82
- prefix: string | (() => string | undefined) | undefined;
83
- value: string | (() => string | undefined) | undefined;
84
- }) | undefined;
85
- headers?: {} | {
86
- [x: string]: string | undefined;
87
- accept?: ((string & {}) | "application/json" | "text/plain" | "application/octet-stream") | undefined;
88
- "content-type"?: ((string & {}) | "application/x-www-form-urlencoded" | "application/json" | "text/plain" | "application/octet-stream" | "multipart/form-data") | undefined;
89
- authorization?: ((string & {}) | `Bearer ${string}` | `Basic ${string}`) | undefined;
90
- } | undefined;
91
- body?: any;
92
- query?: any;
93
- params?: any;
94
- duplex?: "full" | "half" | undefined;
95
- jsonParser: (text: string) => Promise<any> | any;
96
- retry?: _better_fetch_fetch0.RetryOptions | undefined;
97
- retryAttempt?: number | undefined;
98
- output?: (_better_fetch_fetch0.StandardSchemaV1 | typeof Blob | typeof File) | undefined;
99
- errorSchema?: _better_fetch_fetch0.StandardSchemaV1 | undefined;
100
- disableValidation?: boolean | undefined;
101
- disableSignal?: boolean | undefined;
102
- }, unknown, unknown, {}>;
103
- $store: {
104
- notify: (signal?: (Omit<string, "$sessionSignal"> | "$sessionSignal") | undefined) => void;
105
- listen: (signal: Omit<string, "$sessionSignal"> | "$sessionSignal", listener: (value: boolean, oldValue?: boolean | undefined) => void) => void;
106
- atoms: Record<string, nanostores.WritableAtom<any>>;
107
- };
32
+ $fetch: ClientConfig["$fetch"];
33
+ $store: ClientConfig["$store"];
108
34
  $Infer: {
109
- Session: NonNullable<InferClientAPI<Option> extends {
110
- getSession: () => Promise<infer Res>;
111
- } ? Res extends {
112
- data: null;
113
- error: {
114
- message?: string | undefined;
115
- status: number;
116
- statusText: string;
117
- };
118
- } | {
119
- data: infer S;
120
- error: null;
121
- } ? S : Res extends Record<string, any> ? Res : never : never>;
35
+ Session: NonNullable<ClientSession<Option>>;
122
36
  };
123
37
  $ERROR_CODES: PrettifyDeep<InferErrorCodes<Option> & typeof BASE_ERROR_CODES>;
124
38
  };
125
- type AuthClient<Option extends BetterAuthClientOptions> = ReturnType<typeof createAuthClient<Option>>;
39
+ declare function createAuthClient<Option extends BetterAuthClientOptions>(options?: Option | undefined): AuthClient<Option>;
126
40
  //#endregion
127
41
  export { AuthClient, createAuthClient };
@@ -1,10 +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 nanostores from "nanostores";
6
- import * as _better_fetch_fetch0 from "@better-fetch/fetch";
7
- import { BetterFetchError } from "@better-fetch/fetch";
6
+ import { BetterFetchError, BetterFetchResponse } from "@better-fetch/fetch";
8
7
  import { DeepReadonly, Ref } from "vue";
9
8
  export * from "nanostores";
10
9
  export * from "@better-fetch/fetch";
@@ -12,140 +11,45 @@ export * from "@better-fetch/fetch";
12
11
  //#region src/client/vue/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]: () => DeepReadonly<Ref<ReturnType<Atoms[key]["get"]>>> } : {} : {} : {}> : {};
16
- declare function createAuthClient<Option extends BetterAuthClientOptions>(options?: Option | undefined): UnionToIntersection<InferResolvedHooks<Option>> & InferClientAPI<Option> & InferActions<Option> & {
17
- useSession: {
18
- (): DeepReadonly<Ref<{
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;
32
- isPending: boolean;
33
- isRefetching: boolean;
34
- error: BetterFetchError | null;
35
- refetch: (queryParams?: {
36
- query?: SessionQueryParams;
37
- } | undefined) => Promise<void>;
38
- }>>;
39
- <F extends (...args: any) => any>(useFetch: F): Promise<{
40
- data: Ref<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>;
53
- isPending: false;
54
- error: Ref<{
55
- message?: string | undefined;
56
- status: number;
57
- statusText: string;
58
- }>;
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]: () => DeepReadonly<Ref<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
+ type VueUseSession<Option extends BetterAuthClientOptions> = {
22
+ (): DeepReadonly<Ref<{
23
+ data: ClientSession<Option>;
24
+ isPending: boolean;
25
+ isRefetching: boolean;
26
+ error: BetterFetchError | null;
27
+ refetch: (queryParams?: {
28
+ query?: SessionQueryParams;
29
+ } | undefined) => Promise<void>;
30
+ }>>;
31
+ <F extends (...args: any) => any>(useFetch: F): Promise<{
32
+ data: Ref<ClientSession<Option>>;
33
+ isPending: false;
34
+ error: Ref<{
35
+ message?: string | undefined;
36
+ status: number;
37
+ statusText: string;
59
38
  }>;
60
- };
39
+ }>;
40
+ };
41
+ /**
42
+ * Vue client returned by `createAuthClient`.
43
+ */
44
+ type VueAuthClient<Option extends BetterAuthClientOptions> = UnionToIntersection<InferResolvedHooks<Option>> & InferClientAPI<Option> & InferActions<Option> & {
45
+ useSession: VueUseSession<Option>;
61
46
  $Infer: {
62
- Session: NonNullable<InferClientAPI<Option> extends {
63
- getSession: () => Promise<infer Res>;
64
- } ? Res extends {
65
- data: null;
66
- error: {
67
- message?: string | undefined;
68
- status: number;
69
- statusText: string;
70
- };
71
- } | {
72
- data: infer S;
73
- error: null;
74
- } ? S : Res extends Record<string, any> ? Res : never : never>;
75
- };
76
- $fetch: _better_fetch_fetch0.BetterFetch<{
77
- plugins: (_better_fetch_fetch0.BetterFetchPlugin<Record<string, any>> | {
78
- id: string;
79
- name: string;
80
- hooks: {
81
- onSuccess(context: _better_fetch_fetch0.SuccessContext<any>): void;
82
- };
83
- } | {
84
- id: string;
85
- name: string;
86
- hooks: {
87
- onSuccess: ((context: _better_fetch_fetch0.SuccessContext<any>) => Promise<void> | void) | undefined;
88
- onError: ((context: _better_fetch_fetch0.ErrorContext) => Promise<void> | void) | undefined;
89
- onRequest: (<T extends Record<string, any>>(context: _better_fetch_fetch0.RequestContext<T>) => Promise<_better_fetch_fetch0.RequestContext | void> | _better_fetch_fetch0.RequestContext | void) | undefined;
90
- onResponse: ((context: _better_fetch_fetch0.ResponseContext) => Promise<Response | void | _better_fetch_fetch0.ResponseContext> | Response | _better_fetch_fetch0.ResponseContext | void) | undefined;
91
- };
92
- })[];
93
- priority?: RequestPriority | undefined;
94
- cache?: RequestCache | undefined;
95
- credentials?: RequestCredentials;
96
- integrity?: string | undefined;
97
- keepalive?: boolean | undefined;
98
- method: string;
99
- mode?: RequestMode | undefined;
100
- redirect?: RequestRedirect | undefined;
101
- referrer?: string | undefined;
102
- referrerPolicy?: ReferrerPolicy | undefined;
103
- signal?: (AbortSignal | null) | undefined;
104
- window?: null | undefined;
105
- onRetry?: ((response: _better_fetch_fetch0.ResponseContext) => Promise<void> | void) | undefined;
106
- hookOptions?: {
107
- cloneResponse?: boolean;
108
- } | undefined;
109
- timeout?: number | undefined;
110
- customFetchImpl: _better_fetch_fetch0.FetchEsque;
111
- baseURL: string;
112
- throw?: boolean | undefined;
113
- auth?: ({
114
- type: "Bearer";
115
- token: string | Promise<string | undefined> | (() => string | Promise<string | undefined> | undefined) | undefined;
116
- } | {
117
- type: "Basic";
118
- username: string | (() => string | undefined) | undefined;
119
- password: string | (() => string | undefined) | undefined;
120
- } | {
121
- type: "Custom";
122
- prefix: string | (() => string | undefined) | undefined;
123
- value: string | (() => string | undefined) | undefined;
124
- }) | undefined;
125
- headers?: {} | {
126
- [x: string]: string | undefined;
127
- accept?: ((string & {}) | "application/json" | "text/plain" | "application/octet-stream") | undefined;
128
- "content-type"?: ((string & {}) | "application/x-www-form-urlencoded" | "application/json" | "text/plain" | "application/octet-stream" | "multipart/form-data") | undefined;
129
- authorization?: ((string & {}) | `Bearer ${string}` | `Basic ${string}`) | undefined;
130
- } | undefined;
131
- body?: any;
132
- query?: any;
133
- params?: any;
134
- duplex?: "full" | "half" | undefined;
135
- jsonParser: (text: string) => Promise<any> | any;
136
- retry?: _better_fetch_fetch0.RetryOptions | undefined;
137
- retryAttempt?: number | undefined;
138
- output?: (_better_fetch_fetch0.StandardSchemaV1 | typeof Blob | typeof File) | undefined;
139
- errorSchema?: _better_fetch_fetch0.StandardSchemaV1 | undefined;
140
- disableValidation?: boolean | undefined;
141
- disableSignal?: boolean | undefined;
142
- }, unknown, unknown, {}>;
143
- $store: {
144
- notify: (signal?: (Omit<string, "$sessionSignal"> | "$sessionSignal") | undefined) => void;
145
- listen: (signal: Omit<string, "$sessionSignal"> | "$sessionSignal", listener: (value: boolean, oldValue?: boolean | undefined) => void) => void;
146
- atoms: Record<string, nanostores.WritableAtom<any>>;
47
+ Session: NonNullable<ClientSession<Option>>;
147
48
  };
49
+ $fetch: ClientConfig["$fetch"];
50
+ $store: ClientConfig["$store"];
148
51
  $ERROR_CODES: PrettifyDeep<InferErrorCodes<Option> & typeof BASE_ERROR_CODES>;
149
52
  };
53
+ declare function createAuthClient<Option extends BetterAuthClientOptions>(options?: Option | undefined): VueAuthClient<Option>;
150
54
  //#endregion
151
- export { ExtractPluginField, HasRequiredKeys, InferPluginFieldFromTuple, IsAny, OverrideMerge, Prettify, PrettifyDeep, RequiredKeysOf, StripEmptyObjects, type UnionToIntersection, createAuthClient };
55
+ export { ExtractPluginField, HasRequiredKeys, InferPluginFieldFromTuple, IsAny, OverrideMerge, Prettify, PrettifyDeep, RequiredKeysOf, StripEmptyObjects, type UnionToIntersection, VueAuthClient, createAuthClient };
@@ -103,18 +103,8 @@ async function setCookieCache(ctx, session, dontRememberMe) {
103
103
  expiresAt: expiresAtDate
104
104
  }))
105
105
  }), { padding: false });
106
- if (data.length > 4093) {
107
- const sessionStore = createSessionStore(ctx.context.authCookies.sessionData.name, options, ctx);
108
- const cookies = sessionStore.chunk(data, options);
109
- sessionStore.setCookies(cookies);
110
- } else {
111
- const sessionStore = createSessionStore(ctx.context.authCookies.sessionData.name, options, ctx);
112
- if (sessionStore.hasChunks()) {
113
- const cleanCookies = sessionStore.clean();
114
- sessionStore.setCookies(cleanCookies);
115
- }
116
- ctx.setCookie(ctx.context.authCookies.sessionData.name, data, options);
117
- }
106
+ const sessionStore = createSessionStore(ctx.context.authCookies.sessionData.name, options, ctx);
107
+ sessionStore.setCookies(sessionStore.chunk(data, options));
118
108
  if (ctx.context.options.account?.storeAccountCookie && !hasPendingSetCookie(ctx, ctx.context.authCookies.accountData.name)) {
119
109
  const accountData = await getAccountCookie(ctx);
120
110
  if (accountData) if (!shouldBindAccountCookieToSessionUser(ctx.context.options) || accountData.userId === session.user.id) await setAccountCookie(ctx, accountData);
@@ -7,25 +7,8 @@ interface Cookie {
7
7
  attributes: CookieOptions;
8
8
  }
9
9
  declare const createSessionStore: (cookieName: string, cookieOptions: CookieOptions, ctx: GenericEndpointContext) => {
10
- /**
11
- * Get the full session data by joining all chunks
12
- */
13
- getValue(): string;
14
- /**
15
- * Check if there are existing chunks
16
- */
17
- hasChunks(): boolean;
18
- /**
19
- * Chunk a cookie value and return all cookies to set (including cleanup cookies)
20
- */
21
10
  chunk(value: string, options?: Partial<CookieOptions>): Cookie[];
22
- /**
23
- * Get cookies to clean up all chunks
24
- */
25
11
  clean(): Cookie[];
26
- /**
27
- * Set all cookies in the context
28
- */
29
12
  setCookies(cookies: Cookie[]): void;
30
13
  };
31
14
  declare function getChunkedCookie(ctx: GenericEndpointContext, cookieName: string): string | null;