@choiceform/shared-auth 0.1.14 → 0.1.16

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.
Files changed (95) hide show
  1. package/README.md +106 -450
  2. package/dist/api/auth-api.d.ts +28 -0
  3. package/dist/api/auth-api.d.ts.map +1 -0
  4. package/dist/api/auth-api.js +133 -0
  5. package/dist/api/client.d.ts +34 -0
  6. package/dist/api/client.d.ts.map +1 -0
  7. package/dist/api/client.js +104 -0
  8. package/dist/api/index.d.ts +12 -0
  9. package/dist/api/index.d.ts.map +1 -0
  10. package/dist/api/index.js +7 -0
  11. package/dist/api/organization-api.d.ts +96 -0
  12. package/dist/api/organization-api.d.ts.map +1 -0
  13. package/dist/api/organization-api.js +228 -0
  14. package/dist/api/team-api.d.ts +57 -0
  15. package/dist/api/team-api.d.ts.map +1 -0
  16. package/dist/api/team-api.js +118 -0
  17. package/dist/config.d.ts +4 -57
  18. package/dist/config.d.ts.map +1 -1
  19. package/dist/config.js +4 -6
  20. package/dist/core.d.ts +114 -72
  21. package/dist/core.d.ts.map +1 -1
  22. package/dist/core.js +35 -17
  23. package/dist/hooks/use-auth-init.d.ts +10 -0
  24. package/dist/hooks/use-auth-init.d.ts.map +1 -1
  25. package/dist/hooks/use-auth-init.js +59 -31
  26. package/dist/index.d.ts +12 -15
  27. package/dist/index.d.ts.map +1 -1
  28. package/dist/index.js +26 -13
  29. package/dist/init.d.ts +133 -92
  30. package/dist/init.d.ts.map +1 -1
  31. package/dist/init.js +12 -14
  32. package/dist/lib/auth-client.d.ts +49 -54
  33. package/dist/lib/auth-client.d.ts.map +1 -1
  34. package/dist/lib/auth-client.js +10 -16
  35. package/dist/services/companion-team.d.ts +16 -0
  36. package/dist/services/companion-team.d.ts.map +1 -0
  37. package/dist/services/companion-team.js +73 -0
  38. package/dist/services/index.d.ts +5 -0
  39. package/dist/services/index.d.ts.map +1 -0
  40. package/dist/services/index.js +4 -0
  41. package/dist/store/actions.d.ts +45 -33
  42. package/dist/store/actions.d.ts.map +1 -1
  43. package/dist/store/actions.js +135 -106
  44. package/dist/store/index.d.ts +8 -0
  45. package/dist/store/index.d.ts.map +1 -0
  46. package/dist/store/index.js +7 -0
  47. package/dist/store/state.d.ts +10 -7
  48. package/dist/store/state.d.ts.map +1 -1
  49. package/dist/store/state.js +31 -23
  50. package/dist/store/utils.d.ts +22 -71
  51. package/dist/store/utils.d.ts.map +1 -1
  52. package/dist/store/utils.js +28 -146
  53. package/dist/types/auth.d.ts +107 -0
  54. package/dist/types/auth.d.ts.map +1 -0
  55. package/dist/types/auth.js +4 -0
  56. package/dist/types/index.d.ts +8 -0
  57. package/dist/types/index.d.ts.map +1 -0
  58. package/dist/types/index.js +4 -0
  59. package/dist/types/organization.d.ts +111 -0
  60. package/dist/types/organization.d.ts.map +1 -0
  61. package/dist/types/organization.js +4 -0
  62. package/dist/types/team.d.ts +52 -0
  63. package/dist/types/team.d.ts.map +1 -0
  64. package/dist/types/team.js +4 -0
  65. package/dist/types/user.d.ts +44 -0
  66. package/dist/types/user.d.ts.map +1 -0
  67. package/dist/types/user.js +4 -0
  68. package/dist/utils/date.d.ts +10 -0
  69. package/dist/utils/date.d.ts.map +1 -0
  70. package/dist/utils/date.js +13 -0
  71. package/dist/utils/env.d.ts +20 -0
  72. package/dist/utils/env.d.ts.map +1 -0
  73. package/dist/utils/env.js +23 -0
  74. package/dist/utils/index.d.ts +7 -0
  75. package/dist/utils/index.d.ts.map +1 -0
  76. package/dist/utils/index.js +6 -0
  77. package/dist/utils/user-mapper.d.ts +21 -0
  78. package/dist/utils/user-mapper.d.ts.map +1 -0
  79. package/dist/utils/user-mapper.js +55 -0
  80. package/package.json +3 -4
  81. package/dist/components/auth-sync.d.ts +0 -25
  82. package/dist/components/auth-sync.d.ts.map +0 -1
  83. package/dist/components/auth-sync.js +0 -346
  84. package/dist/components/protected-route.d.ts +0 -18
  85. package/dist/components/protected-route.d.ts.map +0 -1
  86. package/dist/components/protected-route.js +0 -34
  87. package/dist/components/sign-in-page.d.ts +0 -21
  88. package/dist/components/sign-in-page.d.ts.map +0 -1
  89. package/dist/components/sign-in-page.js +0 -31
  90. package/dist/core/init-auth-sync.d.ts +0 -7
  91. package/dist/core/init-auth-sync.d.ts.map +0 -1
  92. package/dist/core/init-auth-sync.js +0 -34
  93. package/dist/types.d.ts +0 -87
  94. package/dist/types.d.ts.map +0 -1
  95. package/dist/types.js +0 -4
package/dist/init.d.ts CHANGED
@@ -1,56 +1,50 @@
1
- import type { AuthConfig } from "./config";
2
1
  /**
3
- * 快速初始化认证系统(使用默认配置)
4
- *
5
- * 默认配置:
6
- * - 使用 organizationClient 插件(支持团队功能)
7
- * - 如果用户传入自定义 plugins,则使用用户配置(不会合并默认插件)
2
+ * 快速初始化
8
3
  *
9
- * @param config - 认证配置
10
- * @param config.baseURL - Better Auth API 基础 URL
11
- * @param config.plugins - Better Auth 插件列表,如果不传则使用默认的 organizationClient
12
- * @param config.tokenStorageKey - Token 存储的 localStorage key,默认为 "auth-token"
13
- * @param config.defaultRedirectAfterLogin - (已废弃) 建议在 SignInPage 组件中通过 redirectUrl prop 传入
14
- * @param config.signInPath - (已废弃) 建议在 ProtectedRoute 组件中通过 onUnauthorized 回调处理导航
4
+ * 提供简化的认证初始化接口
5
+ */
6
+ import type { AuthConfig } from "./types";
7
+ /**
8
+ * 快速初始化配置
15
9
  */
16
- export declare function initAuth(config: {
10
+ interface InitAuthConfig {
11
+ /** Better Auth API 基础 URL */
17
12
  baseURL: string;
18
- /** @deprecated 建议在 SignInPage 组件中通过 redirectUrl prop 传入 */
19
- defaultRedirectAfterLogin?: string;
13
+ /** Better Auth 插件列表,如果不传则使用默认的 organizationClient */
20
14
  plugins?: AuthConfig["plugins"];
21
- /** @deprecated 建议在 ProtectedRoute 组件中通过 onUnauthorized 回调处理导航 */
22
- signInPath?: string;
23
- /**
24
- * 跳过错误时的 token 清除(开发环境用)
25
- * 启用后,网络错误、解析错误等不会清除 token,避免开发时频繁登出
26
- */
15
+ /** 跳过错误时的 token 清除(开发环境用) */
27
16
  skipTokenCleanupOnError?: boolean;
17
+ /** Token 存储的 localStorage key */
28
18
  tokenStorageKey?: string;
29
- }): {
19
+ }
20
+ /**
21
+ * 快速初始化认证系统(使用默认配置)
22
+ *
23
+ * 默认配置:
24
+ * - 使用 organizationClient 插件(支持团队功能)
25
+ * - 如果用户传入自定义 plugins,则使用用户配置(不会合并默认插件)
26
+ */
27
+ export declare function initAuth(config: InitAuthConfig): {
30
28
  getCurrentUser: () => import("./types").SessionUser | null;
31
29
  getCurrentUserId: () => string | null;
32
- getCurrentUserIdSafe: () => string | null;
33
30
  isAuthenticated: () => boolean;
34
31
  isLoading: () => boolean;
35
32
  isLoaded: () => boolean;
36
33
  waitForAuth: () => Promise<void>;
37
34
  getAuthToken: () => Promise<string | null>;
35
+ getAuthTokenSync: () => string | null;
38
36
  getAuthHeaders: () => Promise<Record<string, string>>;
37
+ getAuthHeadersSync: () => Record<string, string>;
39
38
  apiClient: {
40
- get(url: string, options?: RequestInit): Promise<Response>;
41
- post(url: string, body?: unknown, options?: RequestInit): Promise<Response>;
42
- put(url: string, body?: unknown, options?: RequestInit): Promise<Response>;
43
- delete(url: string, options?: RequestInit): Promise<Response>;
39
+ get<T = unknown>(path: string, options?: RequestInit): Promise<import("./api").ApiResponse<T>>;
40
+ post<T = unknown>(path: string, body?: unknown, options?: RequestInit): Promise<import("./api").ApiResponse<T>>;
41
+ put<T = unknown>(path: string, body?: unknown, options?: RequestInit): Promise<import("./api").ApiResponse<T>>;
42
+ delete<T = unknown>(path: string, options?: RequestInit): Promise<import("./api").ApiResponse<T>>;
43
+ fetch(path: string, options?: RequestInit): Promise<Response>;
44
44
  };
45
45
  userManager: {
46
- getUser(): import("./types").SessionUser | null;
47
- getUserId(): string | null;
48
- };
49
- authStore: import("@legendapp/state").Observable<import("./types").AuthState>;
50
- tokenStorage: {
51
- save(token: string | null): void;
52
- get(): string | null;
53
- clear(): void;
46
+ getUser: () => import("./types").SessionUser | null;
47
+ getUserId: () => string | null;
54
48
  };
55
49
  authActions: {
56
50
  initialize(user: import("./types").SessionUser | null, isLoaded: boolean): Promise<void>;
@@ -58,18 +52,31 @@ export declare function initAuth(config: {
58
52
  handleUnauthorized(): void;
59
53
  setLoading(loading: boolean): void;
60
54
  setError(error: string | null): void;
61
- signIn(provider?: string, redirectTo?: string): Promise<void>;
55
+ signIn(provider: string, callbackURL: string, newUserCallbackURL?: string, errorCallbackURL?: string): Promise<void>;
56
+ signInWithMagicLink(email: string, callbackURL: string, name?: string, newUserCallbackURL?: string): Promise<boolean>;
57
+ signInWithEmail(email: string, password: string): Promise<boolean>;
58
+ signUpWithEmail(email: string, password: string, name: string): Promise<boolean>;
62
59
  signOut(redirectTo?: string): Promise<void>;
63
60
  updateUser(user: import("./types").SessionUser | null): void;
64
61
  getUser(): import("./types").SessionUser | null;
65
62
  };
66
- authComputed: {
67
- isInitializing: import("@legendapp/state").ObservableBoolean;
63
+ authApi: {
64
+ getSession(token?: string): Promise<import("./types").SessionUser | null>;
65
+ getSessionWithToken(token: string): Promise<import("./types").SessionUser | null>;
66
+ setActiveOrganization(params: import("./types").SetActiveOrganizationRequest, token?: string): Promise<void>;
67
+ setActiveTeam(params: import("./types").SetActiveTeamRequest, token?: string): Promise<void>;
68
+ onboard(token: string): Promise<void>;
69
+ updateUser(data: import("./types").UpdateUserRequest): Promise<import("./types").SessionUser | null>;
70
+ sendMagicLink(params: import("./types").MagicLinkRequest): Promise<{
71
+ status: boolean;
72
+ }>;
73
+ linkCredential(newPassword: string, token?: string): Promise<void>;
74
+ checkEmailExists(email: string): Promise<boolean>;
68
75
  };
69
76
  authClient: {
70
77
  signIn: {
71
78
  social: <FetchOptions extends import("better-auth").ClientFetchOption<Partial<{
72
- provider: unknown;
79
+ provider: (string & {}) | "github" | "apple" | "atlassian" | "cognito" | "discord" | "facebook" | "figma" | "microsoft" | "google" | "huggingface" | "slack" | "spotify" | "twitch" | "twitter" | "dropbox" | "kick" | "linear" | "linkedin" | "gitlab" | "tiktok" | "reddit" | "roblox" | "salesforce" | "vk" | "zoom" | "notion" | "kakao" | "naver" | "line" | "paybin" | "paypal" | "polar" | "vercel";
73
80
  callbackURL?: string | undefined;
74
81
  newUserCallbackURL?: string | undefined;
75
82
  errorCallbackURL?: string | undefined;
@@ -85,8 +92,8 @@ export declare function initAuth(config: {
85
92
  requestSignUp?: boolean | undefined;
86
93
  loginHint?: string | undefined;
87
94
  additionalData?: Record<string, any> | undefined;
88
- }> & Record<string, any>, Partial<Record<string, any>> & Record<string, any>, Record<string, any> | undefined>>(data_0: import("better-auth/client/plugins").Prettify<{
89
- provider: unknown;
95
+ }> & Record<string, any>, Partial<Record<string, any>> & Record<string, any>, Record<string, any> | undefined>>(data_0: import("better-auth/react").Prettify<{
96
+ provider: (string & {}) | "github" | "apple" | "atlassian" | "cognito" | "discord" | "facebook" | "figma" | "microsoft" | "google" | "huggingface" | "slack" | "spotify" | "twitch" | "twitter" | "dropbox" | "kick" | "linear" | "linkedin" | "gitlab" | "tiktok" | "reddit" | "roblox" | "salesforce" | "vk" | "zoom" | "notion" | "kakao" | "naver" | "line" | "paybin" | "paypal" | "polar" | "vercel";
90
97
  callbackURL?: string | undefined;
91
98
  newUserCallbackURL?: string | undefined;
92
99
  errorCallbackURL?: string | undefined;
@@ -105,28 +112,28 @@ export declare function initAuth(config: {
105
112
  } & {
106
113
  fetchOptions?: FetchOptions | undefined;
107
114
  }>, data_1?: FetchOptions | undefined) => Promise<import("@better-fetch/fetch").BetterFetchResponse<NonNullable<{
115
+ redirect: boolean;
116
+ url: string;
117
+ } | {
108
118
  redirect: boolean;
109
119
  token: string;
110
120
  url: undefined;
111
121
  user: {
112
122
  id: string;
113
- email: string;
114
- name: string;
115
- image: string | null | undefined;
116
- emailVerified: boolean;
117
123
  createdAt: Date;
118
124
  updatedAt: Date;
125
+ email: string;
126
+ emailVerified: boolean;
127
+ name: string;
128
+ image?: string | null | undefined | undefined;
119
129
  };
120
- } | {
121
- url: string;
122
- redirect: boolean;
123
130
  }>, {
124
131
  code?: string | undefined;
125
132
  message?: string | undefined;
126
133
  }, FetchOptions["throw"] extends true ? true : false>>;
127
134
  };
128
135
  } & {
129
- signOut: <FetchOptions extends import("better-auth").ClientFetchOption<never, Partial<Record<string, any>> & Record<string, any>, Record<string, any> | undefined>>(data_0?: import("better-auth/client/plugins").Prettify<{
136
+ signOut: <FetchOptions extends import("better-auth").ClientFetchOption<never, Partial<Record<string, any>> & Record<string, any>, Record<string, any> | undefined>>(data_0?: import("better-auth/react").Prettify<{
130
137
  query?: Record<string, any> | undefined;
131
138
  fetchOptions?: FetchOptions | undefined;
132
139
  }> | undefined, data_1?: FetchOptions | undefined) => Promise<import("@better-fetch/fetch").BetterFetchResponse<{
@@ -144,7 +151,7 @@ export declare function initAuth(config: {
144
151
  image?: string | undefined;
145
152
  callbackURL?: string | undefined;
146
153
  rememberMe?: boolean | undefined;
147
- }> & Record<string, any>, Partial<Record<string, any>> & Record<string, any>, Record<string, any> | undefined>>(data_0: import("better-auth/client/plugins").Prettify<{
154
+ }> & Record<string, any>, Partial<Record<string, any>> & Record<string, any>, Record<string, any> | undefined>>(data_0: import("better-auth/react").Prettify<{
148
155
  email: string;
149
156
  name: string;
150
157
  password: string;
@@ -155,23 +162,23 @@ export declare function initAuth(config: {
155
162
  token: null;
156
163
  user: {
157
164
  id: string;
158
- email: string;
159
- name: string;
160
- image: string | null | undefined;
161
- emailVerified: boolean;
162
165
  createdAt: Date;
163
166
  updatedAt: Date;
167
+ email: string;
168
+ emailVerified: boolean;
169
+ name: string;
170
+ image?: string | null | undefined | undefined;
164
171
  };
165
172
  } | {
166
173
  token: string;
167
174
  user: {
168
175
  id: string;
169
- email: string;
170
- name: string;
171
- image: string | null | undefined;
172
- emailVerified: boolean;
173
176
  createdAt: Date;
174
177
  updatedAt: Date;
178
+ email: string;
179
+ emailVerified: boolean;
180
+ name: string;
181
+ image?: string | null | undefined | undefined;
175
182
  };
176
183
  }>, {
177
184
  code?: string | undefined;
@@ -185,7 +192,7 @@ export declare function initAuth(config: {
185
192
  password: string;
186
193
  callbackURL?: string | undefined;
187
194
  rememberMe?: boolean | undefined;
188
- }> & Record<string, any>, Partial<Record<string, any>> & Record<string, any>, Record<string, any> | undefined>>(data_0: import("better-auth/client/plugins").Prettify<{
195
+ }> & Record<string, any>, Partial<Record<string, any>> & Record<string, any>, Record<string, any> | undefined>>(data_0: import("better-auth/react").Prettify<{
189
196
  email: string;
190
197
  password: string;
191
198
  callbackURL?: string | undefined;
@@ -195,15 +202,15 @@ export declare function initAuth(config: {
195
202
  }>, data_1?: FetchOptions | undefined) => Promise<import("@better-fetch/fetch").BetterFetchResponse<{
196
203
  redirect: boolean;
197
204
  token: string;
198
- url: string | undefined;
205
+ url?: string | undefined;
199
206
  user: {
200
207
  id: string;
201
- email: string;
202
- name: string;
203
- image: string | null | undefined;
204
- emailVerified: boolean;
205
208
  createdAt: Date;
206
209
  updatedAt: Date;
210
+ email: string;
211
+ emailVerified: boolean;
212
+ name: string;
213
+ image?: string | null | undefined | undefined;
207
214
  };
208
215
  }, {
209
216
  code?: string | undefined;
@@ -216,7 +223,7 @@ export declare function initAuth(config: {
216
223
  token?: string | undefined;
217
224
  }> & Record<string, any>, Partial<{
218
225
  token?: string | undefined;
219
- }> & Record<string, any>, Record<string, any> | undefined>>(data_0: import("better-auth/client/plugins").Prettify<{
226
+ }> & Record<string, any>, Record<string, any> | undefined>>(data_0: import("better-auth/react").Prettify<{
220
227
  newPassword: string;
221
228
  token?: string | undefined;
222
229
  } & {
@@ -231,7 +238,7 @@ export declare function initAuth(config: {
231
238
  verifyEmail: <FetchOptions extends import("better-auth").ClientFetchOption<never, Partial<{
232
239
  token: string;
233
240
  callbackURL?: string | undefined;
234
- }> & Record<string, any>, Record<string, any> | undefined>>(data_0: import("better-auth/client/plugins").Prettify<{
241
+ }> & Record<string, any>, Record<string, any> | undefined>>(data_0: import("better-auth/react").Prettify<{
235
242
  query: {
236
243
  token: string;
237
244
  callbackURL?: string | undefined;
@@ -247,7 +254,7 @@ export declare function initAuth(config: {
247
254
  sendVerificationEmail: <FetchOptions extends import("better-auth").ClientFetchOption<Partial<{
248
255
  email: string;
249
256
  callbackURL?: string | undefined;
250
- }> & Record<string, any>, Partial<Record<string, any>> & Record<string, any>, Record<string, any> | undefined>>(data_0: import("better-auth/client/plugins").Prettify<{
257
+ }> & Record<string, any>, Partial<Record<string, any>> & Record<string, any>, Record<string, any> | undefined>>(data_0: import("better-auth/react").Prettify<{
251
258
  email: string;
252
259
  callbackURL?: string | undefined;
253
260
  } & {
@@ -262,7 +269,7 @@ export declare function initAuth(config: {
262
269
  changeEmail: <FetchOptions extends import("better-auth").ClientFetchOption<Partial<{
263
270
  newEmail: string;
264
271
  callbackURL?: string | undefined;
265
- }> & Record<string, any>, Partial<Record<string, any>> & Record<string, any>, Record<string, any> | undefined>>(data_0: import("better-auth/client/plugins").Prettify<{
272
+ }> & Record<string, any>, Partial<Record<string, any>> & Record<string, any>, Record<string, any> | undefined>>(data_0: import("better-auth/react").Prettify<{
266
273
  newEmail: string;
267
274
  callbackURL?: string | undefined;
268
275
  } & {
@@ -278,7 +285,7 @@ export declare function initAuth(config: {
278
285
  newPassword: string;
279
286
  currentPassword: string;
280
287
  revokeOtherSessions?: boolean | undefined;
281
- }> & Record<string, any>, Partial<Record<string, any>> & Record<string, any>, Record<string, any> | undefined>>(data_0: import("better-auth/client/plugins").Prettify<{
288
+ }> & Record<string, any>, Partial<Record<string, any>> & Record<string, any>, Record<string, any> | undefined>>(data_0: import("better-auth/react").Prettify<{
282
289
  newPassword: string;
283
290
  currentPassword: string;
284
291
  revokeOtherSessions?: boolean | undefined;
@@ -303,7 +310,7 @@ export declare function initAuth(config: {
303
310
  updateUser: <FetchOptions extends import("better-auth").ClientFetchOption<Partial<Partial<{}> & {
304
311
  name?: string | undefined;
305
312
  image?: string | undefined;
306
- }> & Record<string, any>, Partial<Record<string, any>> & Record<string, any>, Record<string, any> | undefined>>(data_0?: import("better-auth/client/plugins").Prettify<{
313
+ }> & Record<string, any>, Partial<Record<string, any>> & Record<string, any>, Record<string, any> | undefined>>(data_0?: import("better-auth/react").Prettify<{
307
314
  image?: (string | null) | undefined;
308
315
  name?: string | undefined;
309
316
  fetchOptions?: FetchOptions | undefined;
@@ -318,7 +325,7 @@ export declare function initAuth(config: {
318
325
  callbackURL?: string | undefined;
319
326
  password?: string | undefined;
320
327
  token?: string | undefined;
321
- }> & Record<string, any>, Partial<Record<string, any>> & Record<string, any>, Record<string, any> | undefined>>(data_0?: import("better-auth/client/plugins").Prettify<{
328
+ }> & Record<string, any>, Partial<Record<string, any>> & Record<string, any>, Record<string, any> | undefined>>(data_0?: import("better-auth/react").Prettify<{
322
329
  callbackURL?: string | undefined;
323
330
  password?: string | undefined;
324
331
  token?: string | undefined;
@@ -335,7 +342,7 @@ export declare function initAuth(config: {
335
342
  requestPasswordReset: <FetchOptions extends import("better-auth").ClientFetchOption<Partial<{
336
343
  email: string;
337
344
  redirectTo?: string | undefined;
338
- }> & Record<string, any>, Partial<Record<string, any>> & Record<string, any>, Record<string, any> | undefined>>(data_0: import("better-auth/client/plugins").Prettify<{
345
+ }> & Record<string, any>, Partial<Record<string, any>> & Record<string, any>, Record<string, any> | undefined>>(data_0: import("better-auth/react").Prettify<{
339
346
  email: string;
340
347
  redirectTo?: string | undefined;
341
348
  } & {
@@ -353,7 +360,7 @@ export declare function initAuth(config: {
353
360
  callbackURL: string;
354
361
  }> & Record<string, any>, {
355
362
  token: string;
356
- }>>(data_0: import("better-auth/client/plugins").Prettify<{
363
+ }>>(data_0: import("better-auth/react").Prettify<{
357
364
  query: {
358
365
  callbackURL: string;
359
366
  };
@@ -364,10 +371,10 @@ export declare function initAuth(config: {
364
371
  }, FetchOptions["throw"] extends true ? true : false>>;
365
372
  };
366
373
  } & {
367
- listSessions: <FetchOptions extends import("better-auth").ClientFetchOption<never, Partial<Record<string, any>> & Record<string, any>, Record<string, any> | undefined>>(data_0?: import("better-auth/client/plugins").Prettify<{
374
+ listSessions: <FetchOptions extends import("better-auth").ClientFetchOption<never, Partial<Record<string, any>> & Record<string, any>, Record<string, any> | undefined>>(data_0?: import("better-auth/react").Prettify<{
368
375
  query?: Record<string, any> | undefined;
369
376
  fetchOptions?: FetchOptions | undefined;
370
- }> | undefined, data_1?: FetchOptions | undefined) => Promise<import("@better-fetch/fetch").BetterFetchResponse<import("better-auth/client/plugins").Prettify<{
377
+ }> | undefined, data_1?: FetchOptions | undefined) => Promise<import("@better-fetch/fetch").BetterFetchResponse<import("better-auth/react").Prettify<{
371
378
  id: string;
372
379
  createdAt: Date;
373
380
  updatedAt: Date;
@@ -383,7 +390,7 @@ export declare function initAuth(config: {
383
390
  } & {
384
391
  revokeSession: <FetchOptions extends import("better-auth").ClientFetchOption<Partial<{
385
392
  token: string;
386
- }> & Record<string, any>, Partial<Record<string, any>> & Record<string, any>, Record<string, any> | undefined>>(data_0: import("better-auth/client/plugins").Prettify<{
393
+ }> & Record<string, any>, Partial<Record<string, any>> & Record<string, any>, Record<string, any> | undefined>>(data_0: import("better-auth/react").Prettify<{
387
394
  token: string;
388
395
  } & {
389
396
  fetchOptions?: FetchOptions | undefined;
@@ -394,7 +401,7 @@ export declare function initAuth(config: {
394
401
  message?: string | undefined;
395
402
  }, FetchOptions["throw"] extends true ? true : false>>;
396
403
  } & {
397
- revokeSessions: <FetchOptions extends import("better-auth").ClientFetchOption<never, Partial<Record<string, any>> & Record<string, any>, Record<string, any> | undefined>>(data_0?: import("better-auth/client/plugins").Prettify<{
404
+ revokeSessions: <FetchOptions extends import("better-auth").ClientFetchOption<never, Partial<Record<string, any>> & Record<string, any>, Record<string, any> | undefined>>(data_0?: import("better-auth/react").Prettify<{
398
405
  query?: Record<string, any> | undefined;
399
406
  fetchOptions?: FetchOptions | undefined;
400
407
  }> | undefined, data_1?: FetchOptions | undefined) => Promise<import("@better-fetch/fetch").BetterFetchResponse<{
@@ -404,7 +411,7 @@ export declare function initAuth(config: {
404
411
  message?: string | undefined;
405
412
  }, FetchOptions["throw"] extends true ? true : false>>;
406
413
  } & {
407
- revokeOtherSessions: <FetchOptions extends import("better-auth").ClientFetchOption<never, Partial<Record<string, any>> & Record<string, any>, Record<string, any> | undefined>>(data_0?: import("better-auth/client/plugins").Prettify<{
414
+ revokeOtherSessions: <FetchOptions extends import("better-auth").ClientFetchOption<never, Partial<Record<string, any>> & Record<string, any>, Record<string, any> | undefined>>(data_0?: import("better-auth/react").Prettify<{
408
415
  query?: Record<string, any> | undefined;
409
416
  fetchOptions?: FetchOptions | undefined;
410
417
  }> | undefined, data_1?: FetchOptions | undefined) => Promise<import("@better-fetch/fetch").BetterFetchResponse<{
@@ -429,7 +436,7 @@ export declare function initAuth(config: {
429
436
  errorCallbackURL?: string | undefined;
430
437
  disableRedirect?: boolean | undefined;
431
438
  additionalData?: Record<string, any> | undefined;
432
- }> & Record<string, any>, Partial<Record<string, any>> & Record<string, any>, Record<string, any> | undefined>>(data_0: import("better-auth/client/plugins").Prettify<{
439
+ }> & Record<string, any>, Partial<Record<string, any>> & Record<string, any>, Record<string, any> | undefined>>(data_0: import("better-auth/react").Prettify<{
433
440
  provider: unknown;
434
441
  callbackURL?: string | undefined;
435
442
  idToken?: {
@@ -454,7 +461,7 @@ export declare function initAuth(config: {
454
461
  message?: string | undefined;
455
462
  }, FetchOptions["throw"] extends true ? true : false>>;
456
463
  } & {
457
- listAccounts: <FetchOptions extends import("better-auth").ClientFetchOption<never, Partial<Record<string, any>> & Record<string, any>, Record<string, any> | undefined>>(data_0?: import("better-auth/client/plugins").Prettify<{
464
+ listAccounts: <FetchOptions extends import("better-auth").ClientFetchOption<never, Partial<Record<string, any>> & Record<string, any>, Record<string, any> | undefined>>(data_0?: import("better-auth/react").Prettify<{
458
465
  query?: Record<string, any> | undefined;
459
466
  fetchOptions?: FetchOptions | undefined;
460
467
  }> | undefined, data_1?: FetchOptions | undefined) => Promise<import("@better-fetch/fetch").BetterFetchResponse<{
@@ -474,7 +481,7 @@ export declare function initAuth(config: {
474
481
  callback: <FetchOptions extends import("better-auth").ClientFetchOption<never, Partial<{
475
482
  token: string;
476
483
  callbackURL?: string | undefined;
477
- }> & Record<string, any>, Record<string, any> | undefined>>(data_0: import("better-auth/client/plugins").Prettify<{
484
+ }> & Record<string, any>, Record<string, any> | undefined>>(data_0: import("better-auth/react").Prettify<{
478
485
  query: {
479
486
  token: string;
480
487
  callbackURL?: string | undefined;
@@ -492,7 +499,7 @@ export declare function initAuth(config: {
492
499
  unlinkAccount: <FetchOptions extends import("better-auth").ClientFetchOption<Partial<{
493
500
  providerId: string;
494
501
  accountId?: string | undefined;
495
- }> & Record<string, any>, Partial<Record<string, any>> & Record<string, any>, Record<string, any> | undefined>>(data_0: import("better-auth/client/plugins").Prettify<{
502
+ }> & Record<string, any>, Partial<Record<string, any>> & Record<string, any>, Record<string, any> | undefined>>(data_0: import("better-auth/react").Prettify<{
496
503
  providerId: string;
497
504
  accountId?: string | undefined;
498
505
  } & {
@@ -508,7 +515,7 @@ export declare function initAuth(config: {
508
515
  providerId: string;
509
516
  accountId?: string | undefined;
510
517
  userId?: string | undefined;
511
- }> & Record<string, any>, Partial<Record<string, any>> & Record<string, any>, Record<string, any> | undefined>>(data_0: import("better-auth/client/plugins").Prettify<{
518
+ }> & Record<string, any>, Partial<Record<string, any>> & Record<string, any>, Record<string, any> | undefined>>(data_0: import("better-auth/react").Prettify<{
512
519
  providerId: string;
513
520
  accountId?: string | undefined;
514
521
  userId?: string | undefined;
@@ -532,7 +539,7 @@ export declare function initAuth(config: {
532
539
  providerId: string;
533
540
  accountId?: string | undefined;
534
541
  userId?: string | undefined;
535
- }> & Record<string, any>, Partial<Record<string, any>> & Record<string, any>, Record<string, any> | undefined>>(data_0: import("better-auth/client/plugins").Prettify<{
542
+ }> & Record<string, any>, Partial<Record<string, any>> & Record<string, any>, Record<string, any> | undefined>>(data_0: import("better-auth/react").Prettify<{
536
543
  providerId: string;
537
544
  accountId?: string | undefined;
538
545
  userId?: string | undefined;
@@ -550,7 +557,7 @@ export declare function initAuth(config: {
550
557
  } & {
551
558
  accountInfo: <FetchOptions extends import("better-auth").ClientFetchOption<never, Partial<{
552
559
  accountId?: string | undefined;
553
- }> & Record<string, any>, Record<string, any> | undefined>>(data_0?: import("better-auth/client/plugins").Prettify<{
560
+ }> & Record<string, any>, Record<string, any> | undefined>>(data_0?: import("better-auth/react").Prettify<{
554
561
  query?: {
555
562
  accountId?: string | undefined;
556
563
  } | undefined;
@@ -566,7 +573,7 @@ export declare function initAuth(config: {
566
573
  getSession: <FetchOptions extends import("better-auth").ClientFetchOption<never, Partial<{
567
574
  disableCookieCache?: unknown;
568
575
  disableRefresh?: unknown;
569
- }> & Record<string, any>, Record<string, any> | undefined>>(data_0?: import("better-auth/client/plugins").Prettify<{
576
+ }> & Record<string, any>, Record<string, any> | undefined>>(data_0?: import("better-auth/react").Prettify<{
570
577
  query?: {
571
578
  disableCookieCache?: unknown;
572
579
  disableRefresh?: unknown;
@@ -656,12 +663,6 @@ export declare function initAuth(config: {
656
663
  hooks: {
657
664
  onSuccess(context: import("@better-fetch/fetch").SuccessContext<any>): void;
658
665
  };
659
- } | {
660
- id: string;
661
- name: string;
662
- hooks: {
663
- onRequest<T extends Record<string, any>>(context: import("@better-fetch/fetch").RequestContext<T>): void;
664
- };
665
666
  } | {
666
667
  id: string;
667
668
  name: string;
@@ -730,5 +731,45 @@ export declare function initAuth(config: {
730
731
  [x: string]: any;
731
732
  };
732
733
  };
734
+ authComputed: {
735
+ isInitializing: import("@legendapp/state").ObservableBoolean;
736
+ };
737
+ authStore: import("@legendapp/state").Observable<import("./types").AuthState>;
738
+ organizationApi: {
739
+ create(request: import("./types").CreateOrganizationRequest): Promise<import("./types").Organization>;
740
+ update(request: import("./types").UpdateOrganizationRequest): Promise<import("./types").Organization>;
741
+ delete(request: import("./types").DeleteOrganizationRequest): Promise<string>;
742
+ list(): Promise<import("./types").Organization[]>;
743
+ getFullOrganization(): Promise<import("./types").FullOrganization | null>;
744
+ setActive(request: import("./types").SetActiveOrganizationRequest): Promise<import("./types").Organization>;
745
+ checkSlug(request: import("./types").CheckSlugRequest): Promise<boolean>;
746
+ getActiveMember(): Promise<import("./types").Member | null>;
747
+ getActiveMemberRole(): Promise<{
748
+ role: string;
749
+ } | null>;
750
+ removeMember(request: import("./types").RemoveMemberRequest): Promise<import("./types").Member>;
751
+ updateMemberRole(request: import("./types").UpdateMemberRoleRequest): Promise<import("./types").Member>;
752
+ inviteMember(request: import("./types").InviteMemberRequest, inviteLink?: string): Promise<import("./types").Invitation>;
753
+ listInvitations(): Promise<import("./types").Invitation[]>;
754
+ getInvitation(invitationId: string): Promise<import("./types").InvitationDetail | null>;
755
+ cancelInvitation(request: import("./types").CancelInvitationRequest): Promise<void>;
756
+ acceptInvitation(request: import("./types").AcceptInvitationRequest): Promise<import("./types").InvitationResponse>;
757
+ rejectInvitation(request: import("./types").RejectInvitationRequest): Promise<import("./types").InvitationResponse>;
758
+ leave(organizationId: string): Promise<void>;
759
+ };
760
+ teamApi: {
761
+ create(request: import("./types").CreateTeamRequest): Promise<import("./types").Team>;
762
+ list(): Promise<import("./types").Team[]>;
763
+ update(request: import("./types").UpdateTeamRequest): Promise<import("./types").Team>;
764
+ delete(request: import("./types").DeleteTeamRequest): Promise<void>;
765
+ setActive(request: import("./types").SetActiveTeamRequest): Promise<void>;
766
+ listUserTeams(): Promise<import("./types").Team[]>;
767
+ listMembers(teamId: string): Promise<import("./types").TeamMember[]>;
768
+ addMember(request: import("./types").AddTeamMemberRequest): Promise<import("./types").TeamMember>;
769
+ removeMember(request: import("./types").RemoveTeamMemberRequest): Promise<void>;
770
+ leaveTeam(teamId: string): Promise<void>;
771
+ };
772
+ tokenStorage: import("./api").TokenStorage;
733
773
  };
774
+ export {};
734
775
  //# sourceMappingURL=init.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"init.d.ts","sourceRoot":"","sources":["../src/init.ts"],"names":[],"mappings":"AACA,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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iCAgBklE,CAAC;qBAAe,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAA42C,CAAC;;mBAA2D,CAAC;;;;;oBAA8U,CAAC;uBAA8C,CAAC;qBAAmC,CAAC;qBAAmC,CAAC;gBAA+B,CAAC;oBAAuC,CAAC;oBAA2C,CAAC;0BAAwC,CAAC;kBAAwC,CAAC;kBAA8C,CAAC;mBAA+B,CAAC;uBAA0G,CAAC;6BAAuB,CAAC;;mBAAyC,CAAC;;;iBAA2G,CAAC;gBAA+B,CAAC;;;;;;;;;;;;gBAA+e,CAAC;iBAAgB,CAAC;kBAAiB,CAAC;kBAAiB,CAAC;;iBAA8F,CAAC;wBAAkE,CAAC;kBAAgC,CAAC;uBAAmG,CAAC;6BAA2E,CAAC;yBAAwC,CAAC;;;2BAAkF,CAAC;mHAAuL,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAD1xL"}
package/dist/init.js CHANGED
@@ -1,30 +1,28 @@
1
+ /**
2
+ * 快速初始化
3
+ *
4
+ * 提供简化的认证初始化接口
5
+ */
1
6
  import { createAuth } from "./core";
2
- import { organizationClient } from "better-auth/client/plugins";
7
+ import { magicLinkClient, organizationClient } from "better-auth/client/plugins";
3
8
  /**
4
9
  * 快速初始化认证系统(使用默认配置)
5
10
  *
6
11
  * 默认配置:
7
12
  * - 使用 organizationClient 插件(支持团队功能)
8
13
  * - 如果用户传入自定义 plugins,则使用用户配置(不会合并默认插件)
9
- *
10
- * @param config - 认证配置
11
- * @param config.baseURL - Better Auth API 基础 URL
12
- * @param config.plugins - Better Auth 插件列表,如果不传则使用默认的 organizationClient
13
- * @param config.tokenStorageKey - Token 存储的 localStorage key,默认为 "auth-token"
14
- * @param config.defaultRedirectAfterLogin - (已废弃) 建议在 SignInPage 组件中通过 redirectUrl prop 传入
15
- * @param config.signInPath - (已废弃) 建议在 ProtectedRoute 组件中通过 onUnauthorized 回调处理导航
16
14
  */
17
15
  export function initAuth(config) {
18
- const { baseURL, tokenStorageKey, defaultRedirectAfterLogin, signInPath, plugins, skipTokenCleanupOnError } = config;
19
- // 默认使用 organizationClient(支持团队功能)
20
- // 如果用户传入了 plugins,则使用用户配置(不合并默认插件)
21
- const finalPlugins = plugins ?? [organizationClient({ teams: { enabled: true } })];
16
+ const { baseURL, tokenStorageKey, plugins, skipTokenCleanupOnError } = config;
17
+ // 默认插件:magicLinkClient + organizationClient
18
+ const finalPlugins = plugins ?? [
19
+ magicLinkClient(),
20
+ organizationClient({ teams: { enabled: true } }),
21
+ ];
22
22
  return createAuth({
23
23
  baseURL,
24
24
  plugins: finalPlugins,
25
25
  tokenStorageKey: tokenStorageKey || "auth-token",
26
- defaultRedirectAfterLogin,
27
- signInPath,
28
26
  skipTokenCleanupOnError,
29
27
  });
30
28
  }