@choiceform/shared-auth 0.1.16 → 0.1.18
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 +286 -134
- package/dist/__tests__/auth-utils.test.d.ts +5 -0
- package/dist/__tests__/auth-utils.test.d.ts.map +1 -0
- package/dist/__tests__/auth-utils.test.js +96 -0
- package/dist/__tests__/store.test.d.ts +5 -0
- package/dist/__tests__/store.test.d.ts.map +1 -0
- package/dist/__tests__/store.test.js +210 -0
- package/dist/__tests__/user-mapper.test.d.ts +5 -0
- package/dist/__tests__/user-mapper.test.d.ts.map +1 -0
- package/dist/__tests__/user-mapper.test.js +76 -0
- package/dist/api/auth-api.d.ts +93 -9
- package/dist/api/auth-api.d.ts.map +1 -1
- package/dist/api/auth-api.js +219 -80
- package/dist/api/client.d.ts +10 -0
- package/dist/api/client.d.ts.map +1 -1
- package/dist/api/client.js +10 -0
- package/dist/api/organization-api.d.ts +2 -7
- package/dist/api/organization-api.d.ts.map +1 -1
- package/dist/api/organization-api.js +2 -17
- package/dist/api/team-api.d.ts +1 -5
- package/dist/api/team-api.d.ts.map +1 -1
- package/dist/api/team-api.js +5 -11
- package/dist/components/auth-sync.d.ts +27 -0
- package/dist/components/auth-sync.d.ts.map +1 -0
- package/dist/components/auth-sync.js +117 -0
- package/dist/components/protected-route.d.ts +18 -0
- package/dist/components/protected-route.d.ts.map +1 -0
- package/dist/components/protected-route.js +34 -0
- package/dist/components/sign-in-page.d.ts +21 -0
- package/dist/components/sign-in-page.d.ts.map +1 -0
- package/dist/components/sign-in-page.js +31 -0
- package/dist/config.js +1 -1
- package/dist/core.d.ts +148 -71
- package/dist/core.d.ts.map +1 -1
- package/dist/core.js +109 -28
- package/dist/hooks/index.d.ts +8 -0
- package/dist/hooks/index.d.ts.map +1 -0
- package/dist/hooks/index.js +7 -0
- package/dist/hooks/use-auth-init.d.ts +4 -3
- package/dist/hooks/use-auth-init.d.ts.map +1 -1
- package/dist/hooks/use-auth-init.js +18 -30
- package/dist/hooks/use-auth-sync.d.ts +60 -0
- package/dist/hooks/use-auth-sync.d.ts.map +1 -0
- package/dist/hooks/use-auth-sync.js +116 -0
- package/dist/hooks/use-email-verification.d.ts +85 -0
- package/dist/hooks/use-email-verification.d.ts.map +1 -0
- package/dist/hooks/use-email-verification.js +145 -0
- package/dist/hooks/use-protected-route.d.ts +67 -0
- package/dist/hooks/use-protected-route.d.ts.map +1 -0
- package/dist/hooks/use-protected-route.js +102 -0
- package/dist/index.d.ts +12 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +43 -13
- package/dist/init.d.ts +127 -70
- package/dist/init.d.ts.map +1 -1
- package/dist/lib/auth-client.d.ts.map +1 -1
- package/dist/lib/auth-client.js +75 -2
- package/dist/services/auth-service.d.ts +101 -0
- package/dist/services/auth-service.d.ts.map +1 -0
- package/dist/services/auth-service.js +356 -0
- package/dist/services/callback-service.d.ts +33 -0
- package/dist/services/callback-service.d.ts.map +1 -0
- package/dist/services/callback-service.js +473 -0
- package/dist/services/companion-team.d.ts.map +1 -1
- package/dist/services/companion-team.js +41 -39
- package/dist/services/index.d.ts +2 -0
- package/dist/services/index.d.ts.map +1 -1
- package/dist/services/index.js +2 -0
- package/dist/store/actions.d.ts +54 -51
- package/dist/store/actions.d.ts.map +1 -1
- package/dist/store/actions.js +111 -243
- package/dist/store/computed.d.ts +72 -1
- package/dist/store/computed.d.ts.map +1 -1
- package/dist/store/computed.js +90 -3
- package/dist/store/index.d.ts +3 -3
- package/dist/store/index.d.ts.map +1 -1
- package/dist/store/index.js +2 -2
- package/dist/store/state.d.ts +10 -0
- package/dist/store/state.d.ts.map +1 -1
- package/dist/store/state.js +11 -1
- package/dist/store/utils.d.ts +3 -34
- package/dist/store/utils.d.ts.map +1 -1
- package/dist/store/utils.js +2 -22
- package/dist/types/auth.d.ts +106 -0
- package/dist/types/auth.d.ts.map +1 -1
- package/dist/types/callback.d.ts +35 -0
- package/dist/types/callback.d.ts.map +1 -0
- package/dist/types/callback.js +1 -0
- package/dist/types/index.d.ts +4 -3
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/organization.d.ts +19 -3
- package/dist/types/organization.d.ts.map +1 -1
- package/dist/types/team.d.ts +6 -2
- package/dist/types/team.d.ts.map +1 -1
- package/dist/types/user.d.ts +7 -3
- package/dist/types/user.d.ts.map +1 -1
- package/dist/utils/auth-utils.d.ts +60 -0
- package/dist/utils/auth-utils.d.ts.map +1 -0
- package/dist/utils/auth-utils.js +146 -0
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/index.js +1 -0
- package/dist/utils/user-mapper.d.ts.map +1 -1
- package/dist/utils/user-mapper.js +2 -1
- package/package.json +10 -2
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Better Auth 认证状态同步组件
|
|
3
|
+
*
|
|
4
|
+
* 功能说明:
|
|
5
|
+
* - 同步 better-auth 的 session 状态到 Legend State store
|
|
6
|
+
* - 在用户登录成功后自动设置组织/团队上下文
|
|
7
|
+
* - 使用响应式状态监听,确保状态同步的实时性
|
|
8
|
+
*
|
|
9
|
+
* 边缘情况处理:
|
|
10
|
+
* - Session 加载中:设置 loading 状态
|
|
11
|
+
* - Session 错误:清空用户信息,重置团队设置状态
|
|
12
|
+
* - 无 Session 但有用户:保持用户信息(可能从 token 加载)
|
|
13
|
+
* - 用户登出:重置团队设置状态,允许下次登录时重新设置
|
|
14
|
+
*/
|
|
15
|
+
import { useEffect, useRef, useCallback } from "react";
|
|
16
|
+
import { use$ } from "@legendapp/state/react";
|
|
17
|
+
import { mapToSessionUser } from "../utils";
|
|
18
|
+
import { setupCompanionTeam } from "../services";
|
|
19
|
+
/**
|
|
20
|
+
* 将 Better Auth session 数据映射为 SessionUser
|
|
21
|
+
*/
|
|
22
|
+
function mapBetterAuthSession(user, session) {
|
|
23
|
+
return mapToSessionUser({
|
|
24
|
+
banExpires: user.banExpires,
|
|
25
|
+
banReason: user.banReason,
|
|
26
|
+
banned: user.banned,
|
|
27
|
+
createdAt: user.createdAt,
|
|
28
|
+
email: user.email,
|
|
29
|
+
emailVerified: user.emailVerified,
|
|
30
|
+
id: user.id,
|
|
31
|
+
image: user.image,
|
|
32
|
+
name: user.name,
|
|
33
|
+
role: user.role,
|
|
34
|
+
updatedAt: user.updatedAt,
|
|
35
|
+
}, {
|
|
36
|
+
activeOrganizationId: session?.activeOrganizationId,
|
|
37
|
+
activeTeamId: session?.activeTeamId,
|
|
38
|
+
createdAt: session?.createdAt,
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* AuthSync 组件
|
|
43
|
+
*/
|
|
44
|
+
export function AuthSync({ auth }) {
|
|
45
|
+
const { authClient, authActions, tokenStorage, authStore } = auth;
|
|
46
|
+
// 监听 authStore 中的用户状态(响应式)
|
|
47
|
+
const user = use$(authStore.user);
|
|
48
|
+
const isAuthenticated = use$(authStore.isAuthenticated);
|
|
49
|
+
const isLoaded = use$(authStore.isLoaded);
|
|
50
|
+
// 监听 better-auth 的 session
|
|
51
|
+
const sessionResult = authClient.useSession();
|
|
52
|
+
const { data: session, isPending, error, refetch } = sessionResult || {
|
|
53
|
+
data: null,
|
|
54
|
+
isPending: false,
|
|
55
|
+
error: null,
|
|
56
|
+
refetch: undefined,
|
|
57
|
+
};
|
|
58
|
+
// 确保 companion team 设置只执行一次
|
|
59
|
+
const teamSetupRef = useRef(false);
|
|
60
|
+
// 处理 session 更新
|
|
61
|
+
const handleSessionUpdate = useCallback((sessionData) => {
|
|
62
|
+
if (sessionData?.user) {
|
|
63
|
+
try {
|
|
64
|
+
const mappedUser = mapBetterAuthSession(sessionData.user, sessionData.session);
|
|
65
|
+
authActions.initialize(mappedUser, true);
|
|
66
|
+
}
|
|
67
|
+
catch (mappingError) {
|
|
68
|
+
console.error("[AuthSync] Failed to map session user:", mappingError);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}, [authActions]);
|
|
72
|
+
// Effect 1: 同步 better-auth session 到 store
|
|
73
|
+
useEffect(() => {
|
|
74
|
+
if (isPending) {
|
|
75
|
+
authActions.setLoading(true);
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
authActions.setLoading(false);
|
|
79
|
+
if (error) {
|
|
80
|
+
const errorMessage = error instanceof Error
|
|
81
|
+
? error.message
|
|
82
|
+
: typeof error === "string"
|
|
83
|
+
? error
|
|
84
|
+
: "Authentication error";
|
|
85
|
+
authActions.setError(errorMessage);
|
|
86
|
+
authActions.initialize(null, true);
|
|
87
|
+
teamSetupRef.current = false;
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
if (session) {
|
|
91
|
+
handleSessionUpdate(session);
|
|
92
|
+
}
|
|
93
|
+
}, [session, isPending, error, authActions, handleSessionUpdate]);
|
|
94
|
+
// Effect 2: 设置 companion team
|
|
95
|
+
useEffect(() => {
|
|
96
|
+
// 只有在用户已认证且已加载完成时才设置
|
|
97
|
+
if (isLoaded && isAuthenticated && user?.id && !teamSetupRef.current) {
|
|
98
|
+
teamSetupRef.current = true;
|
|
99
|
+
const token = tokenStorage.get();
|
|
100
|
+
if (token && typeof token === "string" && token.trim().length > 0) {
|
|
101
|
+
setupCompanionTeam(auth, token, {
|
|
102
|
+
onComplete: () => refetch?.(),
|
|
103
|
+
onError: () => {
|
|
104
|
+
// 失败后重置,允许重试
|
|
105
|
+
teamSetupRef.current = false;
|
|
106
|
+
},
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
// 用户登出:重置 ref
|
|
111
|
+
if (isLoaded && !isAuthenticated) {
|
|
112
|
+
teamSetupRef.current = false;
|
|
113
|
+
}
|
|
114
|
+
}, [user, isAuthenticated, isLoaded, auth, tokenStorage, refetch]);
|
|
115
|
+
// 不渲染任何内容
|
|
116
|
+
return null;
|
|
117
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import type { AuthInstance } from "../core";
|
|
3
|
+
interface ProtectedRouteProps {
|
|
4
|
+
auth: AuthInstance;
|
|
5
|
+
children: React.ReactNode;
|
|
6
|
+
loadingComponent?: React.ComponentType<{
|
|
7
|
+
message?: string;
|
|
8
|
+
}>;
|
|
9
|
+
loadingMessage?: string;
|
|
10
|
+
onUnauthorized: () => void;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* 路由保护组件
|
|
14
|
+
* 等待认证初始化完成,根据认证状态进行路由保护
|
|
15
|
+
*/
|
|
16
|
+
export declare const ProtectedRoute: React.FC<ProtectedRouteProps>;
|
|
17
|
+
export default ProtectedRoute;
|
|
18
|
+
//# sourceMappingURL=protected-route.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"protected-route.d.ts","sourceRoot":"","sources":["../../src/components/protected-route.tsx"],"names":[],"mappings":"AACA,OAAO,KAAoB,MAAM,OAAO,CAAA;AACxC,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,SAAS,CAAA;AAE3C,UAAU,mBAAmB;IAC3B,IAAI,EAAE,YAAY,CAAA;IAClB,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAA;IACzB,gBAAgB,CAAC,EAAE,KAAK,CAAC,aAAa,CAAC;QAAE,OAAO,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC,CAAA;IAC5D,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB,cAAc,EAAE,MAAM,IAAI,CAAA;CAC3B;AAED;;;GAGG;AACH,eAAO,MAAM,cAAc,EAAE,KAAK,CAAC,EAAE,CAAC,mBAAmB,CAgCxD,CAAA;AAED,eAAe,cAAc,CAAA"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { jsx as _jsx, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
import { observer } from "@legendapp/state/react";
|
|
3
|
+
import { useEffect } from "react";
|
|
4
|
+
/**
|
|
5
|
+
* 路由保护组件
|
|
6
|
+
* 等待认证初始化完成,根据认证状态进行路由保护
|
|
7
|
+
*/
|
|
8
|
+
export const ProtectedRoute = observer(({ children, auth, loadingComponent, loadingMessage, onUnauthorized }) => {
|
|
9
|
+
const { authStore, authComputed } = auth;
|
|
10
|
+
// 检查各种状态
|
|
11
|
+
const isInitializing = authComputed.isInitializing.get();
|
|
12
|
+
const isAuthenticated = authStore.isAuthenticated.get();
|
|
13
|
+
// 当未认证时调用回调
|
|
14
|
+
useEffect(() => {
|
|
15
|
+
if (!isInitializing && !isAuthenticated) {
|
|
16
|
+
onUnauthorized();
|
|
17
|
+
}
|
|
18
|
+
}, [isInitializing, isAuthenticated, onUnauthorized]);
|
|
19
|
+
// 检查初始化状态
|
|
20
|
+
if (isInitializing) {
|
|
21
|
+
if (loadingComponent) {
|
|
22
|
+
const LoadingComponent = loadingComponent;
|
|
23
|
+
return _jsx(LoadingComponent, { message: loadingMessage });
|
|
24
|
+
}
|
|
25
|
+
return _jsx("div", { children: loadingMessage || "Checking authentication..." });
|
|
26
|
+
}
|
|
27
|
+
// 检查认证状态
|
|
28
|
+
if (!isAuthenticated) {
|
|
29
|
+
return null;
|
|
30
|
+
}
|
|
31
|
+
// 所有检查通过,渲染子组件
|
|
32
|
+
return _jsx(_Fragment, { children: children });
|
|
33
|
+
});
|
|
34
|
+
export default ProtectedRoute;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import type { AuthInstance } from "../core";
|
|
3
|
+
interface SignInPageProps {
|
|
4
|
+
afterElement?: React.ReactNode;
|
|
5
|
+
auth: AuthInstance;
|
|
6
|
+
beforeElement?: React.ReactNode;
|
|
7
|
+
className?: string;
|
|
8
|
+
description?: string;
|
|
9
|
+
footerText?: React.ReactNode;
|
|
10
|
+
githubButton?: (isSigningIn: boolean) => React.ReactNode;
|
|
11
|
+
onAuthSuccess?: () => void;
|
|
12
|
+
provider?: string;
|
|
13
|
+
redirectUrl?: string;
|
|
14
|
+
title?: string;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* 登录页面组件
|
|
18
|
+
*/
|
|
19
|
+
export declare function SignInPage({ afterElement, auth, beforeElement, onAuthSuccess, redirectUrl, provider, title, description, githubButton, className, footerText, }: SignInPageProps): import("react/jsx-runtime").JSX.Element;
|
|
20
|
+
export {};
|
|
21
|
+
//# sourceMappingURL=sign-in-page.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sign-in-page.d.ts","sourceRoot":"","sources":["../../src/components/sign-in-page.tsx"],"names":[],"mappings":"AAEA,OAAO,KAA8B,MAAM,OAAO,CAAA;AAClD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,SAAS,CAAA;AAE3C,UAAU,eAAe;IACvB,YAAY,CAAC,EAAE,KAAK,CAAC,SAAS,CAAA;IAC9B,IAAI,EAAE,YAAY,CAAA;IAClB,aAAa,CAAC,EAAE,KAAK,CAAC,SAAS,CAAA;IAC/B,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,UAAU,CAAC,EAAE,KAAK,CAAC,SAAS,CAAA;IAC5B,YAAY,CAAC,EAAE,CAAC,WAAW,EAAE,OAAO,KAAK,KAAK,CAAC,SAAS,CAAA;IACxD,aAAa,CAAC,EAAE,MAAM,IAAI,CAAA;IAC1B,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,KAAK,CAAC,EAAE,MAAM,CAAA;CACf;AAED;;GAEG;AACH,wBAAgB,UAAU,CAAC,EACzB,YAAY,EACZ,IAAI,EACJ,aAAa,EACb,aAAa,EACb,WAA0B,EAC1B,QAAmB,EACnB,KAAK,EACL,WAAW,EACX,YAAY,EACZ,SAAS,EACT,UAAU,GACX,EAAE,eAAe,2CA+CjB"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { Slot } from "@choiceform/design-system";
|
|
3
|
+
import { use$ } from "@legendapp/state/react";
|
|
4
|
+
import { useEffect, useState } from "react";
|
|
5
|
+
/**
|
|
6
|
+
* 登录页面组件
|
|
7
|
+
*/
|
|
8
|
+
export function SignInPage({ afterElement, auth, beforeElement, onAuthSuccess, redirectUrl = "/community", provider = "github", title, description, githubButton, className, footerText, }) {
|
|
9
|
+
const { authStore, authActions } = auth;
|
|
10
|
+
const { isAuthenticated, error } = use$(authStore);
|
|
11
|
+
const [isSigningIn, setIsSigningIn] = useState(false);
|
|
12
|
+
useEffect(() => {
|
|
13
|
+
if (isAuthenticated && onAuthSuccess) {
|
|
14
|
+
onAuthSuccess();
|
|
15
|
+
}
|
|
16
|
+
}, [isAuthenticated, onAuthSuccess]);
|
|
17
|
+
const handleSignIn = async () => {
|
|
18
|
+
// 设置本地 loading 状态
|
|
19
|
+
setIsSigningIn(true);
|
|
20
|
+
try {
|
|
21
|
+
await authActions.signIn(provider, `${window.location.origin}${redirectUrl}`);
|
|
22
|
+
// OAuth 会重定向,所以这里的代码可能不会执行
|
|
23
|
+
// loading 状态会在页面刷新后重置
|
|
24
|
+
}
|
|
25
|
+
catch (error) {
|
|
26
|
+
// 如果出错,重置 loading 状态
|
|
27
|
+
setIsSigningIn(false);
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
return (_jsxs("div", { className: className, children: [beforeElement, title && (_jsxs("div", { className: "flex flex-col gap-2", children: [title && _jsx("p", { className: "text-heading-large", children: title }), description && (_jsx("p", { className: "text-secondary-foreground text-body-large", children: description }))] })), provider === "github" && (_jsx(Slot, { onClick: handleSignIn, children: githubButton?.(isSigningIn) })), error && _jsx("p", { className: "text-danger-foreground mt-2", children: error }), footerText, afterElement] }));
|
|
31
|
+
}
|
package/dist/config.js
CHANGED
package/dist/core.d.ts
CHANGED
|
@@ -1,18 +1,28 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* 认证系统核心
|
|
3
|
+
*
|
|
4
|
+
* 架构设计:
|
|
5
|
+
* - Store Layer: 响应式状态管理(authStore + storeActions)
|
|
6
|
+
* - Service Layer: 业务逻辑(authService)
|
|
7
|
+
* - API Layer: HTTP 请求(apiClient + authApi/organizationApi/teamApi)
|
|
8
|
+
*
|
|
9
|
+
* 使用方式:
|
|
10
|
+
* ```typescript
|
|
11
|
+
* // 初始化
|
|
12
|
+
* const auth = createAuth({ baseURL: 'https://api.example.com' })
|
|
13
|
+
*
|
|
14
|
+
* // 响应式读取状态
|
|
15
|
+
* const user = use$(auth.authStore.user)
|
|
16
|
+
*
|
|
17
|
+
* // 业务操作
|
|
18
|
+
* await auth.authService.signInWithEmail(email, password)
|
|
19
|
+
*
|
|
20
|
+
* // 状态更新
|
|
21
|
+
* auth.storeActions.setUser(user)
|
|
22
|
+
* ```
|
|
3
23
|
*/
|
|
4
|
-
import type { AuthConfig } from "./types";
|
|
24
|
+
import type { AuthConfig, Organization, SetActiveOrganizationRequest, SetActiveTeamRequest } from "./types";
|
|
5
25
|
export declare function createAuth(config: AuthConfig): {
|
|
6
|
-
getCurrentUser: () => import("./types").SessionUser | null;
|
|
7
|
-
getCurrentUserId: () => string | null;
|
|
8
|
-
isAuthenticated: () => boolean;
|
|
9
|
-
isLoading: () => boolean;
|
|
10
|
-
isLoaded: () => boolean;
|
|
11
|
-
waitForAuth: () => Promise<void>;
|
|
12
|
-
getAuthToken: () => Promise<string | null>;
|
|
13
|
-
getAuthTokenSync: () => string | null;
|
|
14
|
-
getAuthHeaders: () => Promise<Record<string, string>>;
|
|
15
|
-
getAuthHeadersSync: () => Record<string, string>;
|
|
16
26
|
apiClient: {
|
|
17
27
|
get<T = unknown>(path: string, options?: RequestInit): Promise<import("./api").ApiResponse<T>>;
|
|
18
28
|
post<T = unknown>(path: string, body?: unknown, options?: RequestInit): Promise<import("./api").ApiResponse<T>>;
|
|
@@ -20,37 +30,131 @@ export declare function createAuth(config: AuthConfig): {
|
|
|
20
30
|
delete<T = unknown>(path: string, options?: RequestInit): Promise<import("./api").ApiResponse<T>>;
|
|
21
31
|
fetch(path: string, options?: RequestInit): Promise<Response>;
|
|
22
32
|
};
|
|
23
|
-
userManager: {
|
|
24
|
-
getUser: () => import("./types").SessionUser | null;
|
|
25
|
-
getUserId: () => string | null;
|
|
26
|
-
};
|
|
27
|
-
authActions: {
|
|
28
|
-
initialize(user: import("./types").SessionUser | null, isLoaded: boolean): Promise<void>;
|
|
29
|
-
fetchSessionWithToken(token: string): Promise<void>;
|
|
30
|
-
handleUnauthorized(): void;
|
|
31
|
-
setLoading(loading: boolean): void;
|
|
32
|
-
setError(error: string | null): void;
|
|
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>;
|
|
37
|
-
signOut(redirectTo?: string): Promise<void>;
|
|
38
|
-
updateUser(user: import("./types").SessionUser | null): void;
|
|
39
|
-
getUser(): import("./types").SessionUser | null;
|
|
40
|
-
};
|
|
41
33
|
authApi: {
|
|
42
|
-
getSession(
|
|
34
|
+
getSession(): Promise<import("./types").SessionUser | null>;
|
|
43
35
|
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
36
|
onboard(token: string): Promise<void>;
|
|
47
37
|
updateUser(data: import("./types").UpdateUserRequest): Promise<import("./types").SessionUser | null>;
|
|
48
38
|
sendMagicLink(params: import("./types").MagicLinkRequest): Promise<{
|
|
49
39
|
status: boolean;
|
|
50
40
|
}>;
|
|
51
|
-
|
|
41
|
+
resendVerificationEmail(email: string, callbackURL?: string): Promise<{
|
|
42
|
+
status: boolean;
|
|
43
|
+
}>;
|
|
52
44
|
checkEmailExists(email: string): Promise<boolean>;
|
|
45
|
+
linkCredential(newPassword: string, token?: string): Promise<void>;
|
|
46
|
+
changePassword(currentPassword: string, newPassword: string, token?: string): Promise<{
|
|
47
|
+
success: boolean;
|
|
48
|
+
}>;
|
|
49
|
+
changeEmail(newEmail: string, callbackURL?: string, token?: string): Promise<{
|
|
50
|
+
success: boolean;
|
|
51
|
+
}>;
|
|
52
|
+
listAccounts(token?: string): Promise<import("./types").Account[]>;
|
|
53
|
+
getOAuthAccountInfo(accountId: string, token?: string): Promise<import("./types").OAuthAccountInfo | null>;
|
|
54
|
+
unlinkAccount(providerId: string, accountId?: string, token?: string): Promise<{
|
|
55
|
+
success: boolean;
|
|
56
|
+
}>;
|
|
57
|
+
deleteUser(password?: string, callbackURL?: string, token?: string): Promise<{
|
|
58
|
+
message: string;
|
|
59
|
+
success: boolean;
|
|
60
|
+
}>;
|
|
61
|
+
listSessions(token?: string): Promise<import("./types").UserSession[]>;
|
|
62
|
+
revokeSession(params: import("./types").RevokeSessionRequest, token?: string): Promise<{
|
|
63
|
+
success: boolean;
|
|
64
|
+
}>;
|
|
65
|
+
};
|
|
66
|
+
organizationApi: {
|
|
67
|
+
create(request: import("./types").CreateOrganizationRequest): Promise<Organization>;
|
|
68
|
+
update(request: import("./types").UpdateOrganizationRequest): Promise<Organization>;
|
|
69
|
+
delete(request: import("./types").DeleteOrganizationRequest): Promise<string>;
|
|
70
|
+
list(): Promise<Organization[]>;
|
|
71
|
+
getFullOrganization(): Promise<import("./types").FullOrganization | null>;
|
|
72
|
+
checkSlug(request: import("./types").CheckSlugRequest): Promise<boolean>;
|
|
73
|
+
getActiveMember(): Promise<import("./types").Member | null>;
|
|
74
|
+
getActiveMemberRole(): Promise<{
|
|
75
|
+
role: string;
|
|
76
|
+
} | null>;
|
|
77
|
+
removeMember(request: import("./types").RemoveMemberRequest): Promise<import("./types").Member>;
|
|
78
|
+
updateMemberRole(request: import("./types").UpdateMemberRoleRequest): Promise<import("./types").Member>;
|
|
79
|
+
inviteMember(request: import("./types").InviteMemberRequest): Promise<import("./types").Invitation>;
|
|
80
|
+
listInvitations(): Promise<import("./types").Invitation[]>;
|
|
81
|
+
getInvitation(invitationId: string): Promise<import("./types").InvitationDetail | null>;
|
|
82
|
+
cancelInvitation(request: import("./types").CancelInvitationRequest): Promise<void>;
|
|
83
|
+
acceptInvitation(request: import("./types").AcceptInvitationRequest): Promise<import("./types").InvitationResponse>;
|
|
84
|
+
rejectInvitation(request: import("./types").RejectInvitationRequest): Promise<import("./types").InvitationResponse>;
|
|
85
|
+
leave(organizationId: string): Promise<void>;
|
|
86
|
+
};
|
|
87
|
+
teamApi: {
|
|
88
|
+
create(request: import("./types").CreateTeamRequest): Promise<import("./types").Team>;
|
|
89
|
+
list(): Promise<import("./types").Team[]>;
|
|
90
|
+
update(request: import("./types").UpdateTeamRequest): Promise<import("./types").Team>;
|
|
91
|
+
delete(request: import("./types").DeleteTeamRequest): Promise<void>;
|
|
92
|
+
listUserTeams(): Promise<import("./types").Team[]>;
|
|
93
|
+
listMembers(teamId: string): Promise<import("./types").TeamMember[]>;
|
|
94
|
+
addMember(request: import("./types").AddTeamMemberRequest): Promise<import("./types").TeamMember>;
|
|
95
|
+
removeMember(request: import("./types").RemoveTeamMemberRequest): Promise<void>;
|
|
96
|
+
leaveTeam(teamId: string): Promise<void>;
|
|
53
97
|
};
|
|
98
|
+
authStore: import("@legendapp/state").Observable<import("./types").AuthState>;
|
|
99
|
+
authComputed: {
|
|
100
|
+
isInitializing: import("@legendapp/state").ObservableBoolean;
|
|
101
|
+
isReady: import("@legendapp/state").ObservableBoolean;
|
|
102
|
+
isUnauthenticated: import("@legendapp/state").ObservableBoolean;
|
|
103
|
+
hasError: import("@legendapp/state").ObservableBoolean;
|
|
104
|
+
userId: import("@legendapp/state").ObservablePrimitive<string | null>;
|
|
105
|
+
userEmail: import("@legendapp/state").ObservablePrimitive<string | null>;
|
|
106
|
+
userName: import("@legendapp/state").ObservablePrimitive<string | null>;
|
|
107
|
+
userImage: import("@legendapp/state").ObservablePrimitive<string | null>;
|
|
108
|
+
emailVerified: import("@legendapp/state").ObservableBoolean;
|
|
109
|
+
activeOrganizationId: import("@legendapp/state").ObservablePrimitive<string | null>;
|
|
110
|
+
activeTeamId: import("@legendapp/state").ObservablePrimitive<string | null>;
|
|
111
|
+
inherentOrganizationId: import("@legendapp/state").ObservablePrimitive<string | null>;
|
|
112
|
+
inherentTeamId: import("@legendapp/state").ObservablePrimitive<string | null>;
|
|
113
|
+
hasActiveOrganization: import("@legendapp/state").ObservableBoolean;
|
|
114
|
+
hasActiveTeam: import("@legendapp/state").ObservableBoolean;
|
|
115
|
+
isInInherentOrganization: import("@legendapp/state").ObservableBoolean;
|
|
116
|
+
isInInherentTeam: import("@legendapp/state").ObservableBoolean;
|
|
117
|
+
};
|
|
118
|
+
tokenStorage: import("./api").TokenStorage;
|
|
119
|
+
storeActions: {
|
|
120
|
+
getUser(): import("./types").SessionUser | null;
|
|
121
|
+
getUserId(): string | null;
|
|
122
|
+
isAuthenticated(): boolean;
|
|
123
|
+
isLoading(): boolean;
|
|
124
|
+
isLoaded(): boolean;
|
|
125
|
+
setUser(user: import("./types").SessionUser | null): void;
|
|
126
|
+
updateUser(updates: Partial<import("./types").SessionUser>): void;
|
|
127
|
+
setLoading(loading: boolean): void;
|
|
128
|
+
setLoaded(loaded: boolean): void;
|
|
129
|
+
setError(error: string | null): void;
|
|
130
|
+
setAuthenticated(user: import("./types").SessionUser): void;
|
|
131
|
+
clearAuth(): void;
|
|
132
|
+
handleUnauthorized(): void;
|
|
133
|
+
setActiveOrganizationId(organizationId: string | null | undefined): void;
|
|
134
|
+
setActiveTeamId(teamId: string | null | undefined): void;
|
|
135
|
+
initialize(user: import("./types").SessionUser | null, isLoaded: boolean): void;
|
|
136
|
+
};
|
|
137
|
+
authService: {
|
|
138
|
+
fetchAndSetSession: (token: string) => Promise<import("./types").SessionUser | null>;
|
|
139
|
+
signInWithOAuth: (provider: string, callbackURL: string, newUserCallbackURL?: string, errorCallbackURL?: string) => Promise<void>;
|
|
140
|
+
signInWithMagicLink: (email: string, callbackURL: string, name?: string, newUserCallbackURL?: string) => Promise<boolean>;
|
|
141
|
+
signInWithEmail: (email: string, password: string) => Promise<{
|
|
142
|
+
emailVerified?: boolean;
|
|
143
|
+
success: boolean;
|
|
144
|
+
}>;
|
|
145
|
+
signUpWithEmail: (email: string, password: string, name: string, callbackURL?: string) => Promise<{
|
|
146
|
+
emailVerified?: boolean;
|
|
147
|
+
success: boolean;
|
|
148
|
+
}>;
|
|
149
|
+
signOut: (redirectTo?: string) => Promise<void>;
|
|
150
|
+
deleteUser: (callbackURL: string, password?: string) => Promise<{
|
|
151
|
+
needsVerification: boolean;
|
|
152
|
+
success: boolean;
|
|
153
|
+
}>;
|
|
154
|
+
};
|
|
155
|
+
setActiveOrganization: (request: SetActiveOrganizationRequest) => Promise<Organization>;
|
|
156
|
+
setActiveTeam: (request: SetActiveTeamRequest) => Promise<void>;
|
|
157
|
+
setActiveOrganizationAndTeam: (organizationId: string, teamId: string) => Promise<Organization>;
|
|
54
158
|
authClient: {
|
|
55
159
|
signIn: {
|
|
56
160
|
social: <FetchOptions extends import("better-auth").ClientFetchOption<Partial<{
|
|
@@ -709,45 +813,18 @@ export declare function createAuth(config: AuthConfig): {
|
|
|
709
813
|
[x: string]: any;
|
|
710
814
|
};
|
|
711
815
|
};
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
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>;
|
|
816
|
+
getCurrentUser: () => import("./types").SessionUser | null;
|
|
817
|
+
getCurrentUserId: () => string | null;
|
|
818
|
+
isAuthenticated: () => boolean;
|
|
819
|
+
isLoading: () => boolean;
|
|
820
|
+
isLoaded: () => boolean;
|
|
821
|
+
getAuthToken: () => string | null;
|
|
822
|
+
getAuthHeaders: () => Record<string, string>;
|
|
823
|
+
waitForAuth: () => Promise<void>;
|
|
824
|
+
userManager: {
|
|
825
|
+
getUser: () => import("./types").SessionUser | null;
|
|
826
|
+
getUserId: () => string | null;
|
|
749
827
|
};
|
|
750
|
-
tokenStorage: import("./api").TokenStorage;
|
|
751
828
|
};
|
|
752
829
|
export type AuthInstance = ReturnType<typeof createAuth>;
|
|
753
830
|
//# 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":"AAAA
|
|
1
|
+
{"version":3,"file":"core.d.ts","sourceRoot":"","sources":["../src/core.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AASH,OAAO,KAAK,EACV,UAAU,EAEV,YAAY,EACZ,4BAA4B,EAC5B,oBAAoB,EAIrB,MAAM,SAAS,CAAA;AAEhB,wBAAgB,UAAU,CAAC,MAAM,EAAE,UAAU;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;yBA8HX,CAAC;;;;yBAeqrD,CAAC;;;;;;;;;qCAzE5sD,4BAA4B,KACpC,OAAO,CAAC,YAAY,CAAC;6BAUc,oBAAoB,KAAG,OAAO,CAAC,IAAI,CAAC;mDAUxD,MAAM,UACd,MAAM,KACb,OAAO,CAAC,YAAY,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iCA1BH,CAAC;qBAAe,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAoDxB,CAAC;;mBAEa,CAAC;;;;;oBAYrB,CAAC;uBACL,CAAA;qBACA,CAAH;qBAAmC,CAAC;gBAEnC,CAAH;oBAAuC,CAAC;oBACR,CAAC;0BAId,CAAC;kBACjB,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;;;;;;;;;;;;;0BAVjkD,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC;;;;;;EAO7C;AAED,MAAM,MAAM,YAAY,GAAG,UAAU,CAAC,OAAO,UAAU,CAAC,CAAA"}
|