@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.
- package/README.md +106 -450
- package/dist/api/auth-api.d.ts +28 -0
- package/dist/api/auth-api.d.ts.map +1 -0
- package/dist/api/auth-api.js +133 -0
- package/dist/api/client.d.ts +34 -0
- package/dist/api/client.d.ts.map +1 -0
- package/dist/api/client.js +104 -0
- package/dist/api/index.d.ts +12 -0
- package/dist/api/index.d.ts.map +1 -0
- package/dist/api/index.js +7 -0
- package/dist/api/organization-api.d.ts +96 -0
- package/dist/api/organization-api.d.ts.map +1 -0
- package/dist/api/organization-api.js +228 -0
- package/dist/api/team-api.d.ts +57 -0
- package/dist/api/team-api.d.ts.map +1 -0
- package/dist/api/team-api.js +118 -0
- package/dist/config.d.ts +4 -57
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +4 -6
- package/dist/core.d.ts +114 -72
- package/dist/core.d.ts.map +1 -1
- package/dist/core.js +35 -17
- package/dist/hooks/use-auth-init.d.ts +10 -0
- package/dist/hooks/use-auth-init.d.ts.map +1 -1
- package/dist/hooks/use-auth-init.js +59 -31
- package/dist/index.d.ts +12 -15
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +26 -13
- package/dist/init.d.ts +133 -92
- package/dist/init.d.ts.map +1 -1
- package/dist/init.js +12 -14
- package/dist/lib/auth-client.d.ts +49 -54
- package/dist/lib/auth-client.d.ts.map +1 -1
- package/dist/lib/auth-client.js +10 -16
- package/dist/services/companion-team.d.ts +16 -0
- package/dist/services/companion-team.d.ts.map +1 -0
- package/dist/services/companion-team.js +73 -0
- package/dist/services/index.d.ts +5 -0
- package/dist/services/index.d.ts.map +1 -0
- package/dist/services/index.js +4 -0
- package/dist/store/actions.d.ts +45 -33
- package/dist/store/actions.d.ts.map +1 -1
- package/dist/store/actions.js +135 -106
- package/dist/store/index.d.ts +8 -0
- package/dist/store/index.d.ts.map +1 -0
- package/dist/store/index.js +7 -0
- package/dist/store/state.d.ts +10 -7
- package/dist/store/state.d.ts.map +1 -1
- package/dist/store/state.js +31 -23
- package/dist/store/utils.d.ts +22 -71
- package/dist/store/utils.d.ts.map +1 -1
- package/dist/store/utils.js +28 -146
- package/dist/types/auth.d.ts +107 -0
- package/dist/types/auth.d.ts.map +1 -0
- package/dist/types/auth.js +4 -0
- package/dist/types/index.d.ts +8 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +4 -0
- package/dist/types/organization.d.ts +111 -0
- package/dist/types/organization.d.ts.map +1 -0
- package/dist/types/organization.js +4 -0
- package/dist/types/team.d.ts +52 -0
- package/dist/types/team.d.ts.map +1 -0
- package/dist/types/team.js +4 -0
- package/dist/types/user.d.ts +44 -0
- package/dist/types/user.d.ts.map +1 -0
- package/dist/types/user.js +4 -0
- package/dist/utils/date.d.ts +10 -0
- package/dist/utils/date.d.ts.map +1 -0
- package/dist/utils/date.js +13 -0
- package/dist/utils/env.d.ts +20 -0
- package/dist/utils/env.d.ts.map +1 -0
- package/dist/utils/env.js +23 -0
- package/dist/utils/index.d.ts +7 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +6 -0
- package/dist/utils/user-mapper.d.ts +21 -0
- package/dist/utils/user-mapper.d.ts.map +1 -0
- package/dist/utils/user-mapper.js +55 -0
- package/package.json +3 -4
- package/dist/components/auth-sync.d.ts +0 -25
- package/dist/components/auth-sync.d.ts.map +0 -1
- package/dist/components/auth-sync.js +0 -346
- package/dist/components/protected-route.d.ts +0 -18
- package/dist/components/protected-route.d.ts.map +0 -1
- package/dist/components/protected-route.js +0 -34
- package/dist/components/sign-in-page.d.ts +0 -21
- package/dist/components/sign-in-page.d.ts.map +0 -1
- package/dist/components/sign-in-page.js +0 -31
- package/dist/core/init-auth-sync.d.ts +0 -7
- package/dist/core/init-auth-sync.d.ts.map +0 -1
- package/dist/core/init-auth-sync.js +0 -34
- package/dist/types.d.ts +0 -87
- package/dist/types.d.ts.map +0 -1
- package/dist/types.js +0 -4
package/dist/core.d.ts
CHANGED
|
@@ -1,32 +1,28 @@
|
|
|
1
|
-
import type { AuthConfig } from "./config";
|
|
2
1
|
/**
|
|
3
|
-
*
|
|
2
|
+
* 认证系统核心
|
|
4
3
|
*/
|
|
4
|
+
import type { AuthConfig } from "./types";
|
|
5
5
|
export declare function createAuth(config: AuthConfig): {
|
|
6
6
|
getCurrentUser: () => import("./types").SessionUser | null;
|
|
7
7
|
getCurrentUserId: () => string | null;
|
|
8
|
-
getCurrentUserIdSafe: () => string | null;
|
|
9
8
|
isAuthenticated: () => boolean;
|
|
10
9
|
isLoading: () => boolean;
|
|
11
10
|
isLoaded: () => boolean;
|
|
12
11
|
waitForAuth: () => Promise<void>;
|
|
13
12
|
getAuthToken: () => Promise<string | null>;
|
|
13
|
+
getAuthTokenSync: () => string | null;
|
|
14
14
|
getAuthHeaders: () => Promise<Record<string, string>>;
|
|
15
|
+
getAuthHeadersSync: () => Record<string, string>;
|
|
15
16
|
apiClient: {
|
|
16
|
-
get(
|
|
17
|
-
post(
|
|
18
|
-
put(
|
|
19
|
-
delete(
|
|
17
|
+
get<T = unknown>(path: string, options?: RequestInit): Promise<import("./api").ApiResponse<T>>;
|
|
18
|
+
post<T = unknown>(path: string, body?: unknown, options?: RequestInit): Promise<import("./api").ApiResponse<T>>;
|
|
19
|
+
put<T = unknown>(path: string, body?: unknown, options?: RequestInit): Promise<import("./api").ApiResponse<T>>;
|
|
20
|
+
delete<T = unknown>(path: string, options?: RequestInit): Promise<import("./api").ApiResponse<T>>;
|
|
21
|
+
fetch(path: string, options?: RequestInit): Promise<Response>;
|
|
20
22
|
};
|
|
21
23
|
userManager: {
|
|
22
|
-
getUser()
|
|
23
|
-
getUserId()
|
|
24
|
-
};
|
|
25
|
-
authStore: import("@legendapp/state").Observable<import("./types").AuthState>;
|
|
26
|
-
tokenStorage: {
|
|
27
|
-
save(token: string | null): void;
|
|
28
|
-
get(): string | null;
|
|
29
|
-
clear(): void;
|
|
24
|
+
getUser: () => import("./types").SessionUser | null;
|
|
25
|
+
getUserId: () => string | null;
|
|
30
26
|
};
|
|
31
27
|
authActions: {
|
|
32
28
|
initialize(user: import("./types").SessionUser | null, isLoaded: boolean): Promise<void>;
|
|
@@ -34,18 +30,31 @@ export declare function createAuth(config: AuthConfig): {
|
|
|
34
30
|
handleUnauthorized(): void;
|
|
35
31
|
setLoading(loading: boolean): void;
|
|
36
32
|
setError(error: string | null): void;
|
|
37
|
-
signIn(provider?: string,
|
|
33
|
+
signIn(provider: string, callbackURL: string, newUserCallbackURL?: string, errorCallbackURL?: string): Promise<void>;
|
|
34
|
+
signInWithMagicLink(email: string, callbackURL: string, name?: string, newUserCallbackURL?: string): Promise<boolean>;
|
|
35
|
+
signInWithEmail(email: string, password: string): Promise<boolean>;
|
|
36
|
+
signUpWithEmail(email: string, password: string, name: string): Promise<boolean>;
|
|
38
37
|
signOut(redirectTo?: string): Promise<void>;
|
|
39
38
|
updateUser(user: import("./types").SessionUser | null): void;
|
|
40
39
|
getUser(): import("./types").SessionUser | null;
|
|
41
40
|
};
|
|
42
|
-
|
|
43
|
-
|
|
41
|
+
authApi: {
|
|
42
|
+
getSession(token?: string): Promise<import("./types").SessionUser | null>;
|
|
43
|
+
getSessionWithToken(token: string): Promise<import("./types").SessionUser | null>;
|
|
44
|
+
setActiveOrganization(params: import("./types").SetActiveOrganizationRequest, token?: string): Promise<void>;
|
|
45
|
+
setActiveTeam(params: import("./types").SetActiveTeamRequest, token?: string): Promise<void>;
|
|
46
|
+
onboard(token: string): Promise<void>;
|
|
47
|
+
updateUser(data: import("./types").UpdateUserRequest): Promise<import("./types").SessionUser | null>;
|
|
48
|
+
sendMagicLink(params: import("./types").MagicLinkRequest): Promise<{
|
|
49
|
+
status: boolean;
|
|
50
|
+
}>;
|
|
51
|
+
linkCredential(newPassword: string, token?: string): Promise<void>;
|
|
52
|
+
checkEmailExists(email: string): Promise<boolean>;
|
|
44
53
|
};
|
|
45
54
|
authClient: {
|
|
46
55
|
signIn: {
|
|
47
56
|
social: <FetchOptions extends import("better-auth").ClientFetchOption<Partial<{
|
|
48
|
-
provider:
|
|
57
|
+
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";
|
|
49
58
|
callbackURL?: string | undefined;
|
|
50
59
|
newUserCallbackURL?: string | undefined;
|
|
51
60
|
errorCallbackURL?: string | undefined;
|
|
@@ -61,8 +70,8 @@ export declare function createAuth(config: AuthConfig): {
|
|
|
61
70
|
requestSignUp?: boolean | undefined;
|
|
62
71
|
loginHint?: string | undefined;
|
|
63
72
|
additionalData?: Record<string, any> | undefined;
|
|
64
|
-
}> & Record<string, any>, Partial<Record<string, any>> & Record<string, any>, Record<string, any> | undefined>>(data_0: import("better-auth/
|
|
65
|
-
provider:
|
|
73
|
+
}> & Record<string, any>, Partial<Record<string, any>> & Record<string, any>, Record<string, any> | undefined>>(data_0: import("better-auth/react").Prettify<{
|
|
74
|
+
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";
|
|
66
75
|
callbackURL?: string | undefined;
|
|
67
76
|
newUserCallbackURL?: string | undefined;
|
|
68
77
|
errorCallbackURL?: string | undefined;
|
|
@@ -81,28 +90,28 @@ export declare function createAuth(config: AuthConfig): {
|
|
|
81
90
|
} & {
|
|
82
91
|
fetchOptions?: FetchOptions | undefined;
|
|
83
92
|
}>, data_1?: FetchOptions | undefined) => Promise<import("@better-fetch/fetch").BetterFetchResponse<NonNullable<{
|
|
93
|
+
redirect: boolean;
|
|
94
|
+
url: string;
|
|
95
|
+
} | {
|
|
84
96
|
redirect: boolean;
|
|
85
97
|
token: string;
|
|
86
98
|
url: undefined;
|
|
87
99
|
user: {
|
|
88
100
|
id: string;
|
|
89
|
-
email: string;
|
|
90
|
-
name: string;
|
|
91
|
-
image: string | null | undefined;
|
|
92
|
-
emailVerified: boolean;
|
|
93
101
|
createdAt: Date;
|
|
94
102
|
updatedAt: Date;
|
|
103
|
+
email: string;
|
|
104
|
+
emailVerified: boolean;
|
|
105
|
+
name: string;
|
|
106
|
+
image?: string | null | undefined | undefined;
|
|
95
107
|
};
|
|
96
|
-
} | {
|
|
97
|
-
url: string;
|
|
98
|
-
redirect: boolean;
|
|
99
108
|
}>, {
|
|
100
109
|
code?: string | undefined;
|
|
101
110
|
message?: string | undefined;
|
|
102
111
|
}, FetchOptions["throw"] extends true ? true : false>>;
|
|
103
112
|
};
|
|
104
113
|
} & {
|
|
105
|
-
signOut: <FetchOptions extends import("better-auth").ClientFetchOption<never, Partial<Record<string, any>> & Record<string, any>, Record<string, any> | undefined>>(data_0?: import("better-auth/
|
|
114
|
+
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<{
|
|
106
115
|
query?: Record<string, any> | undefined;
|
|
107
116
|
fetchOptions?: FetchOptions | undefined;
|
|
108
117
|
}> | undefined, data_1?: FetchOptions | undefined) => Promise<import("@better-fetch/fetch").BetterFetchResponse<{
|
|
@@ -120,7 +129,7 @@ export declare function createAuth(config: AuthConfig): {
|
|
|
120
129
|
image?: string | undefined;
|
|
121
130
|
callbackURL?: string | undefined;
|
|
122
131
|
rememberMe?: boolean | undefined;
|
|
123
|
-
}> & Record<string, any>, Partial<Record<string, any>> & Record<string, any>, Record<string, any> | undefined>>(data_0: import("better-auth/
|
|
132
|
+
}> & Record<string, any>, Partial<Record<string, any>> & Record<string, any>, Record<string, any> | undefined>>(data_0: import("better-auth/react").Prettify<{
|
|
124
133
|
email: string;
|
|
125
134
|
name: string;
|
|
126
135
|
password: string;
|
|
@@ -131,23 +140,23 @@ export declare function createAuth(config: AuthConfig): {
|
|
|
131
140
|
token: null;
|
|
132
141
|
user: {
|
|
133
142
|
id: string;
|
|
134
|
-
email: string;
|
|
135
|
-
name: string;
|
|
136
|
-
image: string | null | undefined;
|
|
137
|
-
emailVerified: boolean;
|
|
138
143
|
createdAt: Date;
|
|
139
144
|
updatedAt: Date;
|
|
145
|
+
email: string;
|
|
146
|
+
emailVerified: boolean;
|
|
147
|
+
name: string;
|
|
148
|
+
image?: string | null | undefined | undefined;
|
|
140
149
|
};
|
|
141
150
|
} | {
|
|
142
151
|
token: string;
|
|
143
152
|
user: {
|
|
144
153
|
id: string;
|
|
145
|
-
email: string;
|
|
146
|
-
name: string;
|
|
147
|
-
image: string | null | undefined;
|
|
148
|
-
emailVerified: boolean;
|
|
149
154
|
createdAt: Date;
|
|
150
155
|
updatedAt: Date;
|
|
156
|
+
email: string;
|
|
157
|
+
emailVerified: boolean;
|
|
158
|
+
name: string;
|
|
159
|
+
image?: string | null | undefined | undefined;
|
|
151
160
|
};
|
|
152
161
|
}>, {
|
|
153
162
|
code?: string | undefined;
|
|
@@ -161,7 +170,7 @@ export declare function createAuth(config: AuthConfig): {
|
|
|
161
170
|
password: string;
|
|
162
171
|
callbackURL?: string | undefined;
|
|
163
172
|
rememberMe?: boolean | undefined;
|
|
164
|
-
}> & Record<string, any>, Partial<Record<string, any>> & Record<string, any>, Record<string, any> | undefined>>(data_0: import("better-auth/
|
|
173
|
+
}> & Record<string, any>, Partial<Record<string, any>> & Record<string, any>, Record<string, any> | undefined>>(data_0: import("better-auth/react").Prettify<{
|
|
165
174
|
email: string;
|
|
166
175
|
password: string;
|
|
167
176
|
callbackURL?: string | undefined;
|
|
@@ -171,15 +180,15 @@ export declare function createAuth(config: AuthConfig): {
|
|
|
171
180
|
}>, data_1?: FetchOptions | undefined) => Promise<import("@better-fetch/fetch").BetterFetchResponse<{
|
|
172
181
|
redirect: boolean;
|
|
173
182
|
token: string;
|
|
174
|
-
url
|
|
183
|
+
url?: string | undefined;
|
|
175
184
|
user: {
|
|
176
185
|
id: string;
|
|
177
|
-
email: string;
|
|
178
|
-
name: string;
|
|
179
|
-
image: string | null | undefined;
|
|
180
|
-
emailVerified: boolean;
|
|
181
186
|
createdAt: Date;
|
|
182
187
|
updatedAt: Date;
|
|
188
|
+
email: string;
|
|
189
|
+
emailVerified: boolean;
|
|
190
|
+
name: string;
|
|
191
|
+
image?: string | null | undefined | undefined;
|
|
183
192
|
};
|
|
184
193
|
}, {
|
|
185
194
|
code?: string | undefined;
|
|
@@ -192,7 +201,7 @@ export declare function createAuth(config: AuthConfig): {
|
|
|
192
201
|
token?: string | undefined;
|
|
193
202
|
}> & Record<string, any>, Partial<{
|
|
194
203
|
token?: string | undefined;
|
|
195
|
-
}> & Record<string, any>, Record<string, any> | undefined>>(data_0: import("better-auth/
|
|
204
|
+
}> & Record<string, any>, Record<string, any> | undefined>>(data_0: import("better-auth/react").Prettify<{
|
|
196
205
|
newPassword: string;
|
|
197
206
|
token?: string | undefined;
|
|
198
207
|
} & {
|
|
@@ -207,7 +216,7 @@ export declare function createAuth(config: AuthConfig): {
|
|
|
207
216
|
verifyEmail: <FetchOptions extends import("better-auth").ClientFetchOption<never, Partial<{
|
|
208
217
|
token: string;
|
|
209
218
|
callbackURL?: string | undefined;
|
|
210
|
-
}> & Record<string, any>, Record<string, any> | undefined>>(data_0: import("better-auth/
|
|
219
|
+
}> & Record<string, any>, Record<string, any> | undefined>>(data_0: import("better-auth/react").Prettify<{
|
|
211
220
|
query: {
|
|
212
221
|
token: string;
|
|
213
222
|
callbackURL?: string | undefined;
|
|
@@ -223,7 +232,7 @@ export declare function createAuth(config: AuthConfig): {
|
|
|
223
232
|
sendVerificationEmail: <FetchOptions extends import("better-auth").ClientFetchOption<Partial<{
|
|
224
233
|
email: string;
|
|
225
234
|
callbackURL?: string | undefined;
|
|
226
|
-
}> & Record<string, any>, Partial<Record<string, any>> & Record<string, any>, Record<string, any> | undefined>>(data_0: import("better-auth/
|
|
235
|
+
}> & Record<string, any>, Partial<Record<string, any>> & Record<string, any>, Record<string, any> | undefined>>(data_0: import("better-auth/react").Prettify<{
|
|
227
236
|
email: string;
|
|
228
237
|
callbackURL?: string | undefined;
|
|
229
238
|
} & {
|
|
@@ -238,7 +247,7 @@ export declare function createAuth(config: AuthConfig): {
|
|
|
238
247
|
changeEmail: <FetchOptions extends import("better-auth").ClientFetchOption<Partial<{
|
|
239
248
|
newEmail: string;
|
|
240
249
|
callbackURL?: string | undefined;
|
|
241
|
-
}> & Record<string, any>, Partial<Record<string, any>> & Record<string, any>, Record<string, any> | undefined>>(data_0: import("better-auth/
|
|
250
|
+
}> & Record<string, any>, Partial<Record<string, any>> & Record<string, any>, Record<string, any> | undefined>>(data_0: import("better-auth/react").Prettify<{
|
|
242
251
|
newEmail: string;
|
|
243
252
|
callbackURL?: string | undefined;
|
|
244
253
|
} & {
|
|
@@ -254,7 +263,7 @@ export declare function createAuth(config: AuthConfig): {
|
|
|
254
263
|
newPassword: string;
|
|
255
264
|
currentPassword: string;
|
|
256
265
|
revokeOtherSessions?: boolean | undefined;
|
|
257
|
-
}> & Record<string, any>, Partial<Record<string, any>> & Record<string, any>, Record<string, any> | undefined>>(data_0: import("better-auth/
|
|
266
|
+
}> & Record<string, any>, Partial<Record<string, any>> & Record<string, any>, Record<string, any> | undefined>>(data_0: import("better-auth/react").Prettify<{
|
|
258
267
|
newPassword: string;
|
|
259
268
|
currentPassword: string;
|
|
260
269
|
revokeOtherSessions?: boolean | undefined;
|
|
@@ -279,7 +288,7 @@ export declare function createAuth(config: AuthConfig): {
|
|
|
279
288
|
updateUser: <FetchOptions extends import("better-auth").ClientFetchOption<Partial<Partial<{}> & {
|
|
280
289
|
name?: string | undefined;
|
|
281
290
|
image?: string | undefined;
|
|
282
|
-
}> & Record<string, any>, Partial<Record<string, any>> & Record<string, any>, Record<string, any> | undefined>>(data_0?: import("better-auth/
|
|
291
|
+
}> & Record<string, any>, Partial<Record<string, any>> & Record<string, any>, Record<string, any> | undefined>>(data_0?: import("better-auth/react").Prettify<{
|
|
283
292
|
image?: (string | null) | undefined;
|
|
284
293
|
name?: string | undefined;
|
|
285
294
|
fetchOptions?: FetchOptions | undefined;
|
|
@@ -294,7 +303,7 @@ export declare function createAuth(config: AuthConfig): {
|
|
|
294
303
|
callbackURL?: string | undefined;
|
|
295
304
|
password?: string | undefined;
|
|
296
305
|
token?: string | undefined;
|
|
297
|
-
}> & Record<string, any>, Partial<Record<string, any>> & Record<string, any>, Record<string, any> | undefined>>(data_0?: import("better-auth/
|
|
306
|
+
}> & Record<string, any>, Partial<Record<string, any>> & Record<string, any>, Record<string, any> | undefined>>(data_0?: import("better-auth/react").Prettify<{
|
|
298
307
|
callbackURL?: string | undefined;
|
|
299
308
|
password?: string | undefined;
|
|
300
309
|
token?: string | undefined;
|
|
@@ -311,7 +320,7 @@ export declare function createAuth(config: AuthConfig): {
|
|
|
311
320
|
requestPasswordReset: <FetchOptions extends import("better-auth").ClientFetchOption<Partial<{
|
|
312
321
|
email: string;
|
|
313
322
|
redirectTo?: string | undefined;
|
|
314
|
-
}> & Record<string, any>, Partial<Record<string, any>> & Record<string, any>, Record<string, any> | undefined>>(data_0: import("better-auth/
|
|
323
|
+
}> & Record<string, any>, Partial<Record<string, any>> & Record<string, any>, Record<string, any> | undefined>>(data_0: import("better-auth/react").Prettify<{
|
|
315
324
|
email: string;
|
|
316
325
|
redirectTo?: string | undefined;
|
|
317
326
|
} & {
|
|
@@ -329,7 +338,7 @@ export declare function createAuth(config: AuthConfig): {
|
|
|
329
338
|
callbackURL: string;
|
|
330
339
|
}> & Record<string, any>, {
|
|
331
340
|
token: string;
|
|
332
|
-
}>>(data_0: import("better-auth/
|
|
341
|
+
}>>(data_0: import("better-auth/react").Prettify<{
|
|
333
342
|
query: {
|
|
334
343
|
callbackURL: string;
|
|
335
344
|
};
|
|
@@ -340,10 +349,10 @@ export declare function createAuth(config: AuthConfig): {
|
|
|
340
349
|
}, FetchOptions["throw"] extends true ? true : false>>;
|
|
341
350
|
};
|
|
342
351
|
} & {
|
|
343
|
-
listSessions: <FetchOptions extends import("better-auth").ClientFetchOption<never, Partial<Record<string, any>> & Record<string, any>, Record<string, any> | undefined>>(data_0?: import("better-auth/
|
|
352
|
+
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<{
|
|
344
353
|
query?: Record<string, any> | undefined;
|
|
345
354
|
fetchOptions?: FetchOptions | undefined;
|
|
346
|
-
}> | undefined, data_1?: FetchOptions | undefined) => Promise<import("@better-fetch/fetch").BetterFetchResponse<import("better-auth/
|
|
355
|
+
}> | undefined, data_1?: FetchOptions | undefined) => Promise<import("@better-fetch/fetch").BetterFetchResponse<import("better-auth/react").Prettify<{
|
|
347
356
|
id: string;
|
|
348
357
|
createdAt: Date;
|
|
349
358
|
updatedAt: Date;
|
|
@@ -359,7 +368,7 @@ export declare function createAuth(config: AuthConfig): {
|
|
|
359
368
|
} & {
|
|
360
369
|
revokeSession: <FetchOptions extends import("better-auth").ClientFetchOption<Partial<{
|
|
361
370
|
token: string;
|
|
362
|
-
}> & Record<string, any>, Partial<Record<string, any>> & Record<string, any>, Record<string, any> | undefined>>(data_0: import("better-auth/
|
|
371
|
+
}> & Record<string, any>, Partial<Record<string, any>> & Record<string, any>, Record<string, any> | undefined>>(data_0: import("better-auth/react").Prettify<{
|
|
363
372
|
token: string;
|
|
364
373
|
} & {
|
|
365
374
|
fetchOptions?: FetchOptions | undefined;
|
|
@@ -370,7 +379,7 @@ export declare function createAuth(config: AuthConfig): {
|
|
|
370
379
|
message?: string | undefined;
|
|
371
380
|
}, FetchOptions["throw"] extends true ? true : false>>;
|
|
372
381
|
} & {
|
|
373
|
-
revokeSessions: <FetchOptions extends import("better-auth").ClientFetchOption<never, Partial<Record<string, any>> & Record<string, any>, Record<string, any> | undefined>>(data_0?: import("better-auth/
|
|
382
|
+
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<{
|
|
374
383
|
query?: Record<string, any> | undefined;
|
|
375
384
|
fetchOptions?: FetchOptions | undefined;
|
|
376
385
|
}> | undefined, data_1?: FetchOptions | undefined) => Promise<import("@better-fetch/fetch").BetterFetchResponse<{
|
|
@@ -380,7 +389,7 @@ export declare function createAuth(config: AuthConfig): {
|
|
|
380
389
|
message?: string | undefined;
|
|
381
390
|
}, FetchOptions["throw"] extends true ? true : false>>;
|
|
382
391
|
} & {
|
|
383
|
-
revokeOtherSessions: <FetchOptions extends import("better-auth").ClientFetchOption<never, Partial<Record<string, any>> & Record<string, any>, Record<string, any> | undefined>>(data_0?: import("better-auth/
|
|
392
|
+
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<{
|
|
384
393
|
query?: Record<string, any> | undefined;
|
|
385
394
|
fetchOptions?: FetchOptions | undefined;
|
|
386
395
|
}> | undefined, data_1?: FetchOptions | undefined) => Promise<import("@better-fetch/fetch").BetterFetchResponse<{
|
|
@@ -405,7 +414,7 @@ export declare function createAuth(config: AuthConfig): {
|
|
|
405
414
|
errorCallbackURL?: string | undefined;
|
|
406
415
|
disableRedirect?: boolean | undefined;
|
|
407
416
|
additionalData?: Record<string, any> | undefined;
|
|
408
|
-
}> & Record<string, any>, Partial<Record<string, any>> & Record<string, any>, Record<string, any> | undefined>>(data_0: import("better-auth/
|
|
417
|
+
}> & Record<string, any>, Partial<Record<string, any>> & Record<string, any>, Record<string, any> | undefined>>(data_0: import("better-auth/react").Prettify<{
|
|
409
418
|
provider: unknown;
|
|
410
419
|
callbackURL?: string | undefined;
|
|
411
420
|
idToken?: {
|
|
@@ -430,7 +439,7 @@ export declare function createAuth(config: AuthConfig): {
|
|
|
430
439
|
message?: string | undefined;
|
|
431
440
|
}, FetchOptions["throw"] extends true ? true : false>>;
|
|
432
441
|
} & {
|
|
433
|
-
listAccounts: <FetchOptions extends import("better-auth").ClientFetchOption<never, Partial<Record<string, any>> & Record<string, any>, Record<string, any> | undefined>>(data_0?: import("better-auth/
|
|
442
|
+
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<{
|
|
434
443
|
query?: Record<string, any> | undefined;
|
|
435
444
|
fetchOptions?: FetchOptions | undefined;
|
|
436
445
|
}> | undefined, data_1?: FetchOptions | undefined) => Promise<import("@better-fetch/fetch").BetterFetchResponse<{
|
|
@@ -450,7 +459,7 @@ export declare function createAuth(config: AuthConfig): {
|
|
|
450
459
|
callback: <FetchOptions extends import("better-auth").ClientFetchOption<never, Partial<{
|
|
451
460
|
token: string;
|
|
452
461
|
callbackURL?: string | undefined;
|
|
453
|
-
}> & Record<string, any>, Record<string, any> | undefined>>(data_0: import("better-auth/
|
|
462
|
+
}> & Record<string, any>, Record<string, any> | undefined>>(data_0: import("better-auth/react").Prettify<{
|
|
454
463
|
query: {
|
|
455
464
|
token: string;
|
|
456
465
|
callbackURL?: string | undefined;
|
|
@@ -468,7 +477,7 @@ export declare function createAuth(config: AuthConfig): {
|
|
|
468
477
|
unlinkAccount: <FetchOptions extends import("better-auth").ClientFetchOption<Partial<{
|
|
469
478
|
providerId: string;
|
|
470
479
|
accountId?: string | undefined;
|
|
471
|
-
}> & Record<string, any>, Partial<Record<string, any>> & Record<string, any>, Record<string, any> | undefined>>(data_0: import("better-auth/
|
|
480
|
+
}> & Record<string, any>, Partial<Record<string, any>> & Record<string, any>, Record<string, any> | undefined>>(data_0: import("better-auth/react").Prettify<{
|
|
472
481
|
providerId: string;
|
|
473
482
|
accountId?: string | undefined;
|
|
474
483
|
} & {
|
|
@@ -484,7 +493,7 @@ export declare function createAuth(config: AuthConfig): {
|
|
|
484
493
|
providerId: string;
|
|
485
494
|
accountId?: string | undefined;
|
|
486
495
|
userId?: string | undefined;
|
|
487
|
-
}> & Record<string, any>, Partial<Record<string, any>> & Record<string, any>, Record<string, any> | undefined>>(data_0: import("better-auth/
|
|
496
|
+
}> & Record<string, any>, Partial<Record<string, any>> & Record<string, any>, Record<string, any> | undefined>>(data_0: import("better-auth/react").Prettify<{
|
|
488
497
|
providerId: string;
|
|
489
498
|
accountId?: string | undefined;
|
|
490
499
|
userId?: string | undefined;
|
|
@@ -508,7 +517,7 @@ export declare function createAuth(config: AuthConfig): {
|
|
|
508
517
|
providerId: string;
|
|
509
518
|
accountId?: string | undefined;
|
|
510
519
|
userId?: string | undefined;
|
|
511
|
-
}> & Record<string, any>, Partial<Record<string, any>> & Record<string, any>, Record<string, any> | undefined>>(data_0: import("better-auth/
|
|
520
|
+
}> & Record<string, any>, Partial<Record<string, any>> & Record<string, any>, Record<string, any> | undefined>>(data_0: import("better-auth/react").Prettify<{
|
|
512
521
|
providerId: string;
|
|
513
522
|
accountId?: string | undefined;
|
|
514
523
|
userId?: string | undefined;
|
|
@@ -526,7 +535,7 @@ export declare function createAuth(config: AuthConfig): {
|
|
|
526
535
|
} & {
|
|
527
536
|
accountInfo: <FetchOptions extends import("better-auth").ClientFetchOption<never, Partial<{
|
|
528
537
|
accountId?: string | undefined;
|
|
529
|
-
}> & Record<string, any>, Record<string, any> | undefined>>(data_0?: import("better-auth/
|
|
538
|
+
}> & Record<string, any>, Record<string, any> | undefined>>(data_0?: import("better-auth/react").Prettify<{
|
|
530
539
|
query?: {
|
|
531
540
|
accountId?: string | undefined;
|
|
532
541
|
} | undefined;
|
|
@@ -542,7 +551,7 @@ export declare function createAuth(config: AuthConfig): {
|
|
|
542
551
|
getSession: <FetchOptions extends import("better-auth").ClientFetchOption<never, Partial<{
|
|
543
552
|
disableCookieCache?: unknown;
|
|
544
553
|
disableRefresh?: unknown;
|
|
545
|
-
}> & Record<string, any>, Record<string, any> | undefined>>(data_0?: import("better-auth/
|
|
554
|
+
}> & Record<string, any>, Record<string, any> | undefined>>(data_0?: import("better-auth/react").Prettify<{
|
|
546
555
|
query?: {
|
|
547
556
|
disableCookieCache?: unknown;
|
|
548
557
|
disableRefresh?: unknown;
|
|
@@ -632,12 +641,6 @@ export declare function createAuth(config: AuthConfig): {
|
|
|
632
641
|
hooks: {
|
|
633
642
|
onSuccess(context: import("@better-fetch/fetch").SuccessContext<any>): void;
|
|
634
643
|
};
|
|
635
|
-
} | {
|
|
636
|
-
id: string;
|
|
637
|
-
name: string;
|
|
638
|
-
hooks: {
|
|
639
|
-
onRequest<T extends Record<string, any>>(context: import("@better-fetch/fetch").RequestContext<T>): void;
|
|
640
|
-
};
|
|
641
644
|
} | {
|
|
642
645
|
id: string;
|
|
643
646
|
name: string;
|
|
@@ -706,6 +709,45 @@ export declare function createAuth(config: AuthConfig): {
|
|
|
706
709
|
[x: string]: any;
|
|
707
710
|
};
|
|
708
711
|
};
|
|
712
|
+
authComputed: {
|
|
713
|
+
isInitializing: import("@legendapp/state").ObservableBoolean;
|
|
714
|
+
};
|
|
715
|
+
authStore: import("@legendapp/state").Observable<import("./types").AuthState>;
|
|
716
|
+
organizationApi: {
|
|
717
|
+
create(request: import("./types").CreateOrganizationRequest): Promise<import("./types").Organization>;
|
|
718
|
+
update(request: import("./types").UpdateOrganizationRequest): Promise<import("./types").Organization>;
|
|
719
|
+
delete(request: import("./types").DeleteOrganizationRequest): Promise<string>;
|
|
720
|
+
list(): Promise<import("./types").Organization[]>;
|
|
721
|
+
getFullOrganization(): Promise<import("./types").FullOrganization | null>;
|
|
722
|
+
setActive(request: import("./types").SetActiveOrganizationRequest): Promise<import("./types").Organization>;
|
|
723
|
+
checkSlug(request: import("./types").CheckSlugRequest): Promise<boolean>;
|
|
724
|
+
getActiveMember(): Promise<import("./types").Member | null>;
|
|
725
|
+
getActiveMemberRole(): Promise<{
|
|
726
|
+
role: string;
|
|
727
|
+
} | null>;
|
|
728
|
+
removeMember(request: import("./types").RemoveMemberRequest): Promise<import("./types").Member>;
|
|
729
|
+
updateMemberRole(request: import("./types").UpdateMemberRoleRequest): Promise<import("./types").Member>;
|
|
730
|
+
inviteMember(request: import("./types").InviteMemberRequest, inviteLink?: string): Promise<import("./types").Invitation>;
|
|
731
|
+
listInvitations(): Promise<import("./types").Invitation[]>;
|
|
732
|
+
getInvitation(invitationId: string): Promise<import("./types").InvitationDetail | null>;
|
|
733
|
+
cancelInvitation(request: import("./types").CancelInvitationRequest): Promise<void>;
|
|
734
|
+
acceptInvitation(request: import("./types").AcceptInvitationRequest): Promise<import("./types").InvitationResponse>;
|
|
735
|
+
rejectInvitation(request: import("./types").RejectInvitationRequest): Promise<import("./types").InvitationResponse>;
|
|
736
|
+
leave(organizationId: string): Promise<void>;
|
|
737
|
+
};
|
|
738
|
+
teamApi: {
|
|
739
|
+
create(request: import("./types").CreateTeamRequest): Promise<import("./types").Team>;
|
|
740
|
+
list(): Promise<import("./types").Team[]>;
|
|
741
|
+
update(request: import("./types").UpdateTeamRequest): Promise<import("./types").Team>;
|
|
742
|
+
delete(request: import("./types").DeleteTeamRequest): Promise<void>;
|
|
743
|
+
setActive(request: import("./types").SetActiveTeamRequest): Promise<void>;
|
|
744
|
+
listUserTeams(): Promise<import("./types").Team[]>;
|
|
745
|
+
listMembers(teamId: string): Promise<import("./types").TeamMember[]>;
|
|
746
|
+
addMember(request: import("./types").AddTeamMemberRequest): Promise<import("./types").TeamMember>;
|
|
747
|
+
removeMember(request: import("./types").RemoveTeamMemberRequest): Promise<void>;
|
|
748
|
+
leaveTeam(teamId: string): Promise<void>;
|
|
749
|
+
};
|
|
750
|
+
tokenStorage: import("./api").TokenStorage;
|
|
709
751
|
};
|
|
710
752
|
export type AuthInstance = ReturnType<typeof createAuth>;
|
|
711
753
|
//# sourceMappingURL=core.d.ts.map
|
package/dist/core.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"core.d.ts","sourceRoot":"","sources":["../src/core.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"core.d.ts","sourceRoot":"","sources":["../src/core.ts"],"names":[],"mappings":"AAAA;;GAEG;AAQH,OAAO,KAAK,EAAE,UAAU,EAAyD,MAAM,SAAS,CAAA;AAEhG,wBAAgB,UAAU,CAAC,MAAM,EAAE,UAAU;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iCA+DqpC,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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAH31J;AAED,MAAM,MAAM,YAAY,GAAG,UAAU,CAAC,OAAO,UAAU,CAAC,CAAA"}
|
package/dist/core.js
CHANGED
|
@@ -1,37 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 认证系统核心
|
|
3
|
+
*/
|
|
1
4
|
import { createAuthClientFromConfig } from "./lib/auth-client";
|
|
2
5
|
import { createAuthStore } from "./store/state";
|
|
3
6
|
import { createAuthActions } from "./store/actions";
|
|
4
7
|
import { createAuthComputed } from "./store/computed";
|
|
5
8
|
import { createBoundAuthUtils } from "./store/utils";
|
|
6
|
-
|
|
7
|
-
* 创建认证系统实例
|
|
8
|
-
*/
|
|
9
|
+
import { createApiClient, createAuthApi, createOrganizationApi, createTeamApi } from "./api";
|
|
9
10
|
export function createAuth(config) {
|
|
10
|
-
// 创建 auth client (传递 tokenStorageKey 以支持 bearer token 认证)
|
|
11
11
|
const authClient = createAuthClientFromConfig(config);
|
|
12
|
-
// 创建 store
|
|
13
12
|
const { authStore, tokenStorage } = createAuthStore({
|
|
14
13
|
tokenStorageKey: config.tokenStorageKey || "auth-token",
|
|
15
14
|
});
|
|
16
|
-
//
|
|
15
|
+
// magicLink 由 magicLinkClient 插件提供,email 是 better-auth 内置方法
|
|
16
|
+
const signIn = authClient.signIn;
|
|
17
|
+
const signUp = authClient.signUp;
|
|
17
18
|
const authActions = createAuthActions(authStore, tokenStorage, config, {
|
|
18
|
-
signIn:
|
|
19
|
+
signIn: {
|
|
20
|
+
email: signIn.email,
|
|
21
|
+
magicLink: signIn.magicLink,
|
|
22
|
+
social: signIn.social,
|
|
23
|
+
},
|
|
19
24
|
signOut: authClient.signOut,
|
|
25
|
+
signUp: signUp ? { email: signUp.email } : undefined,
|
|
20
26
|
});
|
|
21
|
-
// 创建 computed
|
|
22
27
|
const authComputed = createAuthComputed(authStore);
|
|
23
|
-
|
|
24
|
-
const instance = {
|
|
28
|
+
const apiClient = createApiClient({
|
|
25
29
|
authStore,
|
|
26
30
|
tokenStorage,
|
|
31
|
+
unauthorizedHandler: authActions,
|
|
32
|
+
baseURL: config.baseURL,
|
|
33
|
+
});
|
|
34
|
+
const authApi = createAuthApi(apiClient, config.baseURL);
|
|
35
|
+
const organizationApi = createOrganizationApi(apiClient, config.baseURL);
|
|
36
|
+
const teamApi = createTeamApi(apiClient);
|
|
37
|
+
const instance = {
|
|
38
|
+
apiClient,
|
|
27
39
|
authActions,
|
|
28
|
-
|
|
40
|
+
authApi,
|
|
29
41
|
authClient,
|
|
42
|
+
authComputed,
|
|
43
|
+
authStore,
|
|
44
|
+
organizationApi,
|
|
45
|
+
teamApi,
|
|
46
|
+
tokenStorage,
|
|
30
47
|
};
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
};
|
|
48
|
+
const utils = createBoundAuthUtils({
|
|
49
|
+
apiClient,
|
|
50
|
+
authActions,
|
|
51
|
+
authStore,
|
|
52
|
+
tokenStorage,
|
|
53
|
+
});
|
|
54
|
+
return { ...instance, ...utils };
|
|
37
55
|
}
|
|
@@ -1,7 +1,17 @@
|
|
|
1
1
|
import type { AuthInstance } from "../core";
|
|
2
|
+
/**
|
|
3
|
+
* 初始化认证状态(非 hook 版本)
|
|
4
|
+
* 可在 React Router 的 clientLoader 中调用
|
|
5
|
+
*
|
|
6
|
+
* @returns 是否已认证
|
|
7
|
+
*/
|
|
8
|
+
export declare function initializeAuth(auth: AuthInstance): Promise<boolean>;
|
|
2
9
|
/**
|
|
3
10
|
* 认证初始化 hook
|
|
4
11
|
* 在应用启动时检查 URL 中的 token 或 localStorage 中的 token
|
|
12
|
+
*
|
|
13
|
+
* 注意:在 React Router Framework 模式下,应使用 initializeAuth 函数
|
|
14
|
+
* 在 clientLoader 中调用,而不是使用此 hook
|
|
5
15
|
*/
|
|
6
16
|
export declare function useAuthInit(auth: AuthInstance): void;
|
|
7
17
|
//# sourceMappingURL=use-auth-init.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-auth-init.d.ts","sourceRoot":"","sources":["../../src/hooks/use-auth-init.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,SAAS,CAAA;AAE3C
|
|
1
|
+
{"version":3,"file":"use-auth-init.d.ts","sourceRoot":"","sources":["../../src/hooks/use-auth-init.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,SAAS,CAAA;AAE3C;;;;;GAKG;AACH,wBAAsB,cAAc,CAAC,IAAI,EAAE,YAAY,GAAG,OAAO,CAAC,OAAO,CAAC,CAoDzE;AAED;;;;;;GAMG;AACH,wBAAgB,WAAW,CAAC,IAAI,EAAE,YAAY,QAQ7C"}
|