@better-auth/expo 1.4.0-beta.9 → 1.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/client.d.mts CHANGED
@@ -1,113 +1,167 @@
1
- import * as better_auth_types from 'better-auth/types';
2
- import * as _better_fetch_fetch from '@better-fetch/fetch';
3
- import { BetterFetchOption } from '@better-fetch/fetch';
1
+ import * as _better_fetch_fetch0 from "@better-fetch/fetch";
2
+ import { ClientFetchOption, ClientStore } from "@better-auth/core";
3
+ import { FocusManager, OnlineManager } from "better-auth/client";
4
4
 
5
+ //#region src/focus-manager.d.ts
6
+ declare function setupExpoFocusManager(): FocusManager;
7
+ //#endregion
8
+ //#region src/online-manager.d.ts
9
+ declare function setupExpoOnlineManager(): OnlineManager;
10
+ //#endregion
11
+ //#region src/client.d.ts
5
12
  interface CookieAttributes {
6
- value: string;
7
- expires?: Date;
8
- "max-age"?: number;
9
- domain?: string;
10
- path?: string;
11
- secure?: boolean;
12
- httpOnly?: boolean;
13
- sameSite?: "Strict" | "Lax" | "None";
13
+ value: string;
14
+ expires?: Date | undefined;
15
+ "max-age"?: number | undefined;
16
+ domain?: string | undefined;
17
+ path?: string | undefined;
18
+ secure?: boolean | undefined;
19
+ httpOnly?: boolean | undefined;
20
+ sameSite?: ("Strict" | "Lax" | "None") | undefined;
14
21
  }
15
22
  declare function parseSetCookieHeader(header: string): Map<string, CookieAttributes>;
16
23
  interface ExpoClientOptions {
17
- scheme?: string;
18
- storage: {
19
- setItem: (key: string, value: string) => any;
20
- getItem: (key: string) => string | null;
21
- };
22
- storagePrefix?: string;
23
- disableCache?: boolean;
24
+ scheme?: string | undefined;
25
+ storage: {
26
+ setItem: (key: string, value: string) => any;
27
+ getItem: (key: string) => string | null;
28
+ };
29
+ /**
30
+ * Prefix for local storage keys (e.g., "my-app_cookie", "my-app_session_data")
31
+ * @default "better-auth"
32
+ */
33
+ storagePrefix?: string | undefined;
34
+ /**
35
+ * Prefix(es) for server cookie names to filter (e.g., "better-auth.session_token")
36
+ * This is used to identify which cookies belong to better-auth to prevent
37
+ * infinite refetching when third-party cookies are set.
38
+ * Can be a single string or an array of strings to match multiple prefixes.
39
+ * @default "better-auth"
40
+ * @example "better-auth"
41
+ * @example ["better-auth", "my-app"]
42
+ */
43
+ cookiePrefix?: string | string[] | undefined;
44
+ disableCache?: boolean | undefined;
24
45
  }
25
- declare function getSetCookie(header: string, prevCookie?: string): string;
46
+ declare function getSetCookie(header: string, prevCookie?: string | undefined): string;
26
47
  declare function getCookie(cookie: string): string;
48
+ /**
49
+ * Check if the Set-Cookie header contains better-auth cookies.
50
+ * This prevents infinite refetching when non-better-auth cookies (like third-party cookies) change.
51
+ *
52
+ * Supports multiple cookie naming patterns:
53
+ * - Default: "better-auth.session_token", "better-auth-passkey", "__Secure-better-auth.session_token"
54
+ * - Custom prefix: "myapp.session_token", "myapp-passkey", "__Secure-myapp.session_token"
55
+ * - Custom full names: "my_custom_session_token", "custom_session_data"
56
+ * - No prefix (cookiePrefix=""): matches any cookie with known suffixes
57
+ * - Multiple prefixes: ["better-auth", "my-app"] matches cookies starting with any of the prefixes
58
+ *
59
+ * @param setCookieHeader - The Set-Cookie header value
60
+ * @param cookiePrefix - The cookie prefix(es) to check for. Can be a string, array of strings, or empty string.
61
+ * @returns true if the header contains better-auth cookies, false otherwise
62
+ */
63
+ declare function hasBetterAuthCookies(setCookieHeader: string, cookiePrefix: string | string[]): boolean;
64
+ /**
65
+ * Expo secure store does not support colons in the keys.
66
+ * This function replaces colons with underscores.
67
+ *
68
+ * @see https://github.com/better-auth/better-auth/issues/5426
69
+ *
70
+ * @param name cookie name to be saved in the storage
71
+ * @returns normalized cookie name
72
+ */
73
+ declare function normalizeCookieName(name: string): string;
74
+ declare function storageAdapter(storage: {
75
+ getItem: (name: string) => string | null;
76
+ setItem: (name: string, value: string) => void;
77
+ }): {
78
+ getItem: (name: string) => string | null;
79
+ setItem: (name: string, value: string) => void;
80
+ };
27
81
  declare const expoClient: (opts: ExpoClientOptions) => {
28
- id: "expo";
29
- getActions(_: _better_fetch_fetch.BetterFetch, $store: better_auth_types.ClientStore): {
30
- /**
31
- * Get the stored cookie.
32
- *
33
- * You can use this to get the cookie stored in the device and use it in your fetch
34
- * requests.
35
- *
36
- * @example
37
- * ```ts
38
- * const cookie = client.getCookie();
39
- * fetch("https://api.example.com", {
40
- * headers: {
41
- * cookie,
42
- * },
43
- * });
44
- */
45
- getCookie: () => string;
82
+ id: "expo";
83
+ getActions(_: _better_fetch_fetch0.BetterFetch, $store: ClientStore): {
84
+ /**
85
+ * Get the stored cookie.
86
+ *
87
+ * You can use this to get the cookie stored in the device and use it in your fetch
88
+ * requests.
89
+ *
90
+ * @example
91
+ * ```ts
92
+ * const cookie = client.getCookie();
93
+ * fetch("https://api.example.com", {
94
+ * headers: {
95
+ * cookie,
96
+ * },
97
+ * });
98
+ */
99
+ getCookie: () => string;
100
+ };
101
+ fetchPlugins: {
102
+ id: string;
103
+ name: string;
104
+ hooks: {
105
+ onSuccess(context: _better_fetch_fetch0.SuccessContext<any>): Promise<void>;
46
106
  };
47
- fetchPlugins: {
48
- id: string;
49
- name: string;
50
- hooks: {
51
- onSuccess(context: _better_fetch_fetch.SuccessContext<any>): Promise<void>;
52
- };
53
- init(url: string, options: {
54
- cache?: RequestCache | undefined;
55
- credentials?: RequestCredentials | undefined;
56
- headers?: (HeadersInit & (HeadersInit | {
57
- accept: "application/json" | "text/plain" | "application/octet-stream";
58
- "content-type": "application/json" | "text/plain" | "application/x-www-form-urlencoded" | "multipart/form-data" | "application/octet-stream";
59
- authorization: "Bearer" | "Basic";
60
- })) | undefined;
61
- integrity?: string | undefined;
62
- keepalive?: boolean | undefined;
63
- method?: string | undefined;
64
- mode?: RequestMode | undefined;
65
- priority?: RequestPriority | undefined;
66
- redirect?: RequestRedirect | undefined;
67
- referrer?: string | undefined;
68
- referrerPolicy?: ReferrerPolicy | undefined;
69
- signal?: (AbortSignal | null) | undefined;
70
- window?: null | undefined;
71
- onRequest?: (<T extends Record<string, any>>(context: _better_fetch_fetch.RequestContext<T>) => Promise<_better_fetch_fetch.RequestContext | void> | _better_fetch_fetch.RequestContext | void) | undefined;
72
- onResponse?: ((context: _better_fetch_fetch.ResponseContext) => Promise<Response | void | _better_fetch_fetch.ResponseContext> | Response | _better_fetch_fetch.ResponseContext | void) | undefined;
73
- onSuccess?: ((context: _better_fetch_fetch.SuccessContext<any>) => Promise<void> | void) | undefined;
74
- onError?: ((context: _better_fetch_fetch.ErrorContext) => Promise<void> | void) | undefined;
75
- onRetry?: ((response: _better_fetch_fetch.ResponseContext) => Promise<void> | void) | undefined;
76
- hookOptions?: {
77
- cloneResponse?: boolean;
78
- } | undefined;
79
- timeout?: number | undefined;
80
- customFetchImpl?: _better_fetch_fetch.FetchEsque | undefined;
81
- plugins?: _better_fetch_fetch.BetterFetchPlugin[] | undefined;
82
- baseURL?: string | undefined;
83
- throw?: boolean | undefined;
84
- auth?: ({
85
- type: "Bearer";
86
- token: string | Promise<string | undefined> | (() => string | Promise<string | undefined> | undefined) | undefined;
87
- } | {
88
- type: "Basic";
89
- username: string | (() => string | undefined) | undefined;
90
- password: string | (() => string | undefined) | undefined;
91
- } | {
92
- type: "Custom";
93
- prefix: string | (() => string | undefined) | undefined;
94
- value: string | (() => string | undefined) | undefined;
95
- }) | undefined;
96
- body?: any;
97
- query?: any;
98
- params?: any;
99
- duplex?: "full" | "half" | undefined;
100
- jsonParser?: ((text: string) => Promise<any> | any) | undefined;
101
- retry?: _better_fetch_fetch.RetryOptions | undefined;
102
- retryAttempt?: number | undefined;
103
- output?: (_better_fetch_fetch.StandardSchemaV1 | typeof Blob | typeof File) | undefined;
104
- errorSchema?: _better_fetch_fetch.StandardSchemaV1 | undefined;
105
- disableValidation?: boolean | undefined;
106
- } | undefined): Promise<{
107
- url: string;
108
- options: BetterFetchOption;
109
- }>;
110
- }[];
107
+ init(url: string, options: {
108
+ method?: string | undefined;
109
+ headers?: (HeadersInit & (HeadersInit | {
110
+ accept: "application/json" | "text/plain" | "application/octet-stream";
111
+ "content-type": "application/json" | "text/plain" | "application/x-www-form-urlencoded" | "multipart/form-data" | "application/octet-stream";
112
+ authorization: "Bearer" | "Basic";
113
+ })) | undefined;
114
+ redirect?: RequestRedirect | undefined;
115
+ cache?: RequestCache | undefined;
116
+ credentials?: RequestCredentials | undefined;
117
+ integrity?: string | undefined;
118
+ keepalive?: boolean | undefined;
119
+ mode?: RequestMode | undefined;
120
+ priority?: RequestPriority | undefined;
121
+ referrer?: string | undefined;
122
+ referrerPolicy?: ReferrerPolicy | undefined;
123
+ signal?: (AbortSignal | null) | undefined;
124
+ window?: null | undefined;
125
+ onRequest?: (<T extends Record<string, any>>(context: _better_fetch_fetch0.RequestContext<T>) => Promise<_better_fetch_fetch0.RequestContext | void> | _better_fetch_fetch0.RequestContext | void) | undefined;
126
+ onResponse?: ((context: _better_fetch_fetch0.ResponseContext) => Promise<Response | void | _better_fetch_fetch0.ResponseContext> | Response | _better_fetch_fetch0.ResponseContext | void) | undefined;
127
+ onSuccess?: ((context: _better_fetch_fetch0.SuccessContext<any>) => Promise<void> | void) | undefined;
128
+ onError?: ((context: _better_fetch_fetch0.ErrorContext) => Promise<void> | void) | undefined;
129
+ onRetry?: ((response: _better_fetch_fetch0.ResponseContext) => Promise<void> | void) | undefined;
130
+ hookOptions?: {
131
+ cloneResponse?: boolean;
132
+ } | undefined;
133
+ timeout?: number | undefined;
134
+ customFetchImpl?: _better_fetch_fetch0.FetchEsque | undefined;
135
+ plugins?: _better_fetch_fetch0.BetterFetchPlugin[] | undefined;
136
+ baseURL?: string | undefined;
137
+ throw?: boolean | undefined;
138
+ auth?: ({
139
+ type: "Bearer";
140
+ token: string | Promise<string | undefined> | (() => string | Promise<string | undefined> | undefined) | undefined;
141
+ } | {
142
+ type: "Basic";
143
+ username: string | (() => string | undefined) | undefined;
144
+ password: string | (() => string | undefined) | undefined;
145
+ } | {
146
+ type: "Custom";
147
+ prefix: string | (() => string | undefined) | undefined;
148
+ value: string | (() => string | undefined) | undefined;
149
+ }) | undefined;
150
+ body?: any;
151
+ query?: any;
152
+ params?: any;
153
+ duplex?: "full" | "half" | undefined;
154
+ jsonParser?: ((text: string) => Promise<any> | any) | undefined;
155
+ retry?: _better_fetch_fetch0.RetryOptions | undefined;
156
+ retryAttempt?: number | undefined;
157
+ output?: (_better_fetch_fetch0.StandardSchemaV1 | typeof Blob | typeof File) | undefined;
158
+ errorSchema?: _better_fetch_fetch0.StandardSchemaV1 | undefined;
159
+ disableValidation?: boolean | undefined;
160
+ } | undefined): Promise<{
161
+ url: string;
162
+ options: ClientFetchOption;
163
+ }>;
164
+ }[];
111
165
  };
112
-
113
- export { expoClient, getCookie, getSetCookie, parseSetCookieHeader };
166
+ //#endregion
167
+ export { expoClient, getCookie, getSetCookie, hasBetterAuthCookies, normalizeCookieName, parseSetCookieHeader, setupExpoFocusManager, setupExpoOnlineManager, storageAdapter };