@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,210 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Store 测试
|
|
3
|
+
*/
|
|
4
|
+
import { describe, it, expect, beforeEach, vi } from "vitest";
|
|
5
|
+
import { createAuthStore, createTokenStorage } from "../store/state";
|
|
6
|
+
import { createStoreActions } from "../store/actions";
|
|
7
|
+
import { createAuthComputed } from "../store/computed";
|
|
8
|
+
// Mock localStorage
|
|
9
|
+
const localStorageMock = (() => {
|
|
10
|
+
let store = {};
|
|
11
|
+
return {
|
|
12
|
+
getItem: vi.fn((key) => store[key] || null),
|
|
13
|
+
setItem: vi.fn((key, value) => {
|
|
14
|
+
store[key] = value;
|
|
15
|
+
}),
|
|
16
|
+
removeItem: vi.fn((key) => {
|
|
17
|
+
delete store[key];
|
|
18
|
+
}),
|
|
19
|
+
clear: vi.fn(() => {
|
|
20
|
+
store = {};
|
|
21
|
+
}),
|
|
22
|
+
};
|
|
23
|
+
})();
|
|
24
|
+
Object.defineProperty(globalThis, "localStorage", { value: localStorageMock });
|
|
25
|
+
describe("createTokenStorage", () => {
|
|
26
|
+
beforeEach(() => {
|
|
27
|
+
localStorageMock.clear();
|
|
28
|
+
vi.clearAllMocks();
|
|
29
|
+
});
|
|
30
|
+
it("应该保存和获取 token", () => {
|
|
31
|
+
const storage = createTokenStorage("test-token");
|
|
32
|
+
storage.save("my-token");
|
|
33
|
+
expect(localStorageMock.setItem).toHaveBeenCalledWith("test-token", "my-token");
|
|
34
|
+
localStorageMock.getItem.mockReturnValue("my-token");
|
|
35
|
+
expect(storage.get()).toBe("my-token");
|
|
36
|
+
});
|
|
37
|
+
it("应该清除 token", () => {
|
|
38
|
+
const storage = createTokenStorage("test-token");
|
|
39
|
+
storage.clear();
|
|
40
|
+
expect(localStorageMock.removeItem).toHaveBeenCalledWith("test-token");
|
|
41
|
+
});
|
|
42
|
+
it("应该处理 null token", () => {
|
|
43
|
+
const storage = createTokenStorage("test-token");
|
|
44
|
+
storage.save(null);
|
|
45
|
+
expect(localStorageMock.removeItem).toHaveBeenCalledWith("test-token");
|
|
46
|
+
});
|
|
47
|
+
});
|
|
48
|
+
describe("createAuthStore", () => {
|
|
49
|
+
beforeEach(() => {
|
|
50
|
+
localStorageMock.clear();
|
|
51
|
+
vi.clearAllMocks();
|
|
52
|
+
});
|
|
53
|
+
it("应该创建初始状态", () => {
|
|
54
|
+
const { authStore } = createAuthStore({ tokenStorageKey: "test-token" });
|
|
55
|
+
expect(authStore.user.get()).toBeNull();
|
|
56
|
+
expect(authStore.isAuthenticated.get()).toBe(false);
|
|
57
|
+
expect(authStore.isLoaded.get()).toBe(false);
|
|
58
|
+
expect(authStore.loading.get()).toBe(false);
|
|
59
|
+
expect(authStore.error.get()).toBeNull();
|
|
60
|
+
});
|
|
61
|
+
it("应该从 localStorage 读取初始 token", () => {
|
|
62
|
+
localStorageMock.getItem.mockReturnValue("stored-token");
|
|
63
|
+
const { authStore } = createAuthStore({ tokenStorageKey: "test-token" });
|
|
64
|
+
expect(authStore.token.get()).toBe("stored-token");
|
|
65
|
+
});
|
|
66
|
+
});
|
|
67
|
+
describe("createStoreActions", () => {
|
|
68
|
+
let authStore;
|
|
69
|
+
let tokenStorage;
|
|
70
|
+
let storeActions;
|
|
71
|
+
const mockUser = {
|
|
72
|
+
id: "user-123",
|
|
73
|
+
email: "test@example.com",
|
|
74
|
+
name: "Test User",
|
|
75
|
+
emailVerified: true,
|
|
76
|
+
createdAt: "2024-01-01",
|
|
77
|
+
updatedAt: "2024-01-01",
|
|
78
|
+
metadata: {},
|
|
79
|
+
};
|
|
80
|
+
beforeEach(() => {
|
|
81
|
+
localStorageMock.clear();
|
|
82
|
+
vi.clearAllMocks();
|
|
83
|
+
const store = createAuthStore({ tokenStorageKey: "test-token" });
|
|
84
|
+
authStore = store.authStore;
|
|
85
|
+
tokenStorage = store.tokenStorage;
|
|
86
|
+
storeActions = createStoreActions(authStore, tokenStorage);
|
|
87
|
+
});
|
|
88
|
+
it("应该设置用户", () => {
|
|
89
|
+
storeActions.setUser(mockUser);
|
|
90
|
+
expect(authStore.user.get()).toEqual(mockUser);
|
|
91
|
+
expect(authStore.isAuthenticated.get()).toBe(true);
|
|
92
|
+
});
|
|
93
|
+
it("应该清除用户", () => {
|
|
94
|
+
storeActions.setUser(mockUser);
|
|
95
|
+
storeActions.setUser(null);
|
|
96
|
+
expect(authStore.user.get()).toBeNull();
|
|
97
|
+
expect(authStore.isAuthenticated.get()).toBe(false);
|
|
98
|
+
});
|
|
99
|
+
it("应该更新用户", () => {
|
|
100
|
+
storeActions.setUser(mockUser);
|
|
101
|
+
storeActions.updateUser({ name: "New Name" });
|
|
102
|
+
expect(authStore.user.get()?.name).toBe("New Name");
|
|
103
|
+
expect(authStore.user.get()?.email).toBe("test@example.com");
|
|
104
|
+
});
|
|
105
|
+
it("应该设置 loading 状态", () => {
|
|
106
|
+
storeActions.setLoading(true);
|
|
107
|
+
expect(authStore.loading.get()).toBe(true);
|
|
108
|
+
storeActions.setLoading(false);
|
|
109
|
+
expect(authStore.loading.get()).toBe(false);
|
|
110
|
+
});
|
|
111
|
+
it("应该设置错误", () => {
|
|
112
|
+
storeActions.setError("Test error");
|
|
113
|
+
expect(authStore.error.get()).toBe("Test error");
|
|
114
|
+
storeActions.setError(null);
|
|
115
|
+
expect(authStore.error.get()).toBeNull();
|
|
116
|
+
});
|
|
117
|
+
it("应该清除认证状态", () => {
|
|
118
|
+
storeActions.setUser(mockUser);
|
|
119
|
+
storeActions.setError("some error");
|
|
120
|
+
storeActions.clearAuth();
|
|
121
|
+
expect(authStore.user.get()).toBeNull();
|
|
122
|
+
expect(authStore.isAuthenticated.get()).toBe(false);
|
|
123
|
+
expect(authStore.isLoaded.get()).toBe(true);
|
|
124
|
+
expect(authStore.loading.get()).toBe(false);
|
|
125
|
+
});
|
|
126
|
+
it("应该设置活跃组织 ID", () => {
|
|
127
|
+
storeActions.setUser(mockUser);
|
|
128
|
+
storeActions.setActiveOrganizationId("org-123");
|
|
129
|
+
expect(authStore.user.get()?.activeOrganizationId).toBe("org-123");
|
|
130
|
+
});
|
|
131
|
+
it("应该设置活跃团队 ID", () => {
|
|
132
|
+
storeActions.setUser(mockUser);
|
|
133
|
+
storeActions.setActiveTeamId("team-123");
|
|
134
|
+
expect(authStore.user.get()?.activeTeamId).toBe("team-123");
|
|
135
|
+
});
|
|
136
|
+
it("应该返回正确的状态", () => {
|
|
137
|
+
expect(storeActions.isAuthenticated()).toBe(false);
|
|
138
|
+
expect(storeActions.isLoading()).toBe(false);
|
|
139
|
+
expect(storeActions.isLoaded()).toBe(false);
|
|
140
|
+
expect(storeActions.getUser()).toBeNull();
|
|
141
|
+
expect(storeActions.getUserId()).toBeNull();
|
|
142
|
+
storeActions.setAuthenticated(mockUser);
|
|
143
|
+
expect(storeActions.isAuthenticated()).toBe(true);
|
|
144
|
+
expect(storeActions.getUser()).toEqual(mockUser);
|
|
145
|
+
expect(storeActions.getUserId()).toBe("user-123");
|
|
146
|
+
});
|
|
147
|
+
});
|
|
148
|
+
describe("createAuthComputed", () => {
|
|
149
|
+
let authStore;
|
|
150
|
+
const mockUser = {
|
|
151
|
+
id: "user-123",
|
|
152
|
+
email: "test@example.com",
|
|
153
|
+
name: "Test User",
|
|
154
|
+
emailVerified: true,
|
|
155
|
+
createdAt: "2024-01-01",
|
|
156
|
+
updatedAt: "2024-01-01",
|
|
157
|
+
activeOrganizationId: "org-123",
|
|
158
|
+
activeTeamId: "team-123",
|
|
159
|
+
inherentOrganizationId: "inherent-org",
|
|
160
|
+
inherentTeamId: "inherent-team",
|
|
161
|
+
metadata: {},
|
|
162
|
+
};
|
|
163
|
+
beforeEach(() => {
|
|
164
|
+
localStorageMock.clear();
|
|
165
|
+
vi.clearAllMocks();
|
|
166
|
+
const store = createAuthStore({ tokenStorageKey: "test-token" });
|
|
167
|
+
authStore = store.authStore;
|
|
168
|
+
});
|
|
169
|
+
it("应该计算 isInitializing", () => {
|
|
170
|
+
const computed = createAuthComputed(authStore);
|
|
171
|
+
expect(computed.isInitializing.get()).toBe(true);
|
|
172
|
+
authStore.isLoaded.set(true);
|
|
173
|
+
expect(computed.isInitializing.get()).toBe(false);
|
|
174
|
+
});
|
|
175
|
+
it("应该计算 isReady", () => {
|
|
176
|
+
const computed = createAuthComputed(authStore);
|
|
177
|
+
expect(computed.isReady.get()).toBe(false);
|
|
178
|
+
authStore.isLoaded.set(true);
|
|
179
|
+
authStore.isAuthenticated.set(true);
|
|
180
|
+
expect(computed.isReady.get()).toBe(true);
|
|
181
|
+
});
|
|
182
|
+
it("应该计算用户信息", () => {
|
|
183
|
+
const computed = createAuthComputed(authStore);
|
|
184
|
+
authStore.user.set(mockUser);
|
|
185
|
+
expect(computed.userId.get()).toBe("user-123");
|
|
186
|
+
expect(computed.userEmail.get()).toBe("test@example.com");
|
|
187
|
+
expect(computed.userName.get()).toBe("Test User");
|
|
188
|
+
expect(computed.emailVerified.get()).toBe(true);
|
|
189
|
+
});
|
|
190
|
+
it("应该计算组织和团队信息", () => {
|
|
191
|
+
const computed = createAuthComputed(authStore);
|
|
192
|
+
authStore.user.set(mockUser);
|
|
193
|
+
expect(computed.activeOrganizationId.get()).toBe("org-123");
|
|
194
|
+
expect(computed.activeTeamId.get()).toBe("team-123");
|
|
195
|
+
expect(computed.inherentOrganizationId.get()).toBe("inherent-org");
|
|
196
|
+
expect(computed.inherentTeamId.get()).toBe("inherent-team");
|
|
197
|
+
expect(computed.hasActiveOrganization.get()).toBe(true);
|
|
198
|
+
expect(computed.hasActiveTeam.get()).toBe(true);
|
|
199
|
+
});
|
|
200
|
+
it("应该计算是否在伴生组织/团队中", () => {
|
|
201
|
+
const computed = createAuthComputed(authStore);
|
|
202
|
+
authStore.user.set({
|
|
203
|
+
...mockUser,
|
|
204
|
+
activeOrganizationId: "inherent-org",
|
|
205
|
+
activeTeamId: "inherent-team",
|
|
206
|
+
});
|
|
207
|
+
expect(computed.isInInherentOrganization.get()).toBe(true);
|
|
208
|
+
expect(computed.isInInherentTeam.get()).toBe(true);
|
|
209
|
+
});
|
|
210
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"user-mapper.test.d.ts","sourceRoot":"","sources":["../../src/__tests__/user-mapper.test.ts"],"names":[],"mappings":"AAAA;;GAEG"}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* User Mapper 测试
|
|
3
|
+
*/
|
|
4
|
+
import { describe, it, expect } from "vitest";
|
|
5
|
+
import { extractSessionUser } from "../utils/user-mapper";
|
|
6
|
+
describe("extractSessionUser", () => {
|
|
7
|
+
it("应该从完整的 session 数据中提取用户", () => {
|
|
8
|
+
const sessionData = {
|
|
9
|
+
user: {
|
|
10
|
+
id: "user-123",
|
|
11
|
+
email: "test@example.com",
|
|
12
|
+
name: "Test User",
|
|
13
|
+
emailVerified: true,
|
|
14
|
+
image: "https://example.com/avatar.png",
|
|
15
|
+
createdAt: new Date("2024-01-01"),
|
|
16
|
+
updatedAt: new Date("2024-01-02"),
|
|
17
|
+
inherentOrganizationId: "org-123",
|
|
18
|
+
inherentTeamId: "team-123",
|
|
19
|
+
metadata: { theme: "dark" },
|
|
20
|
+
},
|
|
21
|
+
session: {
|
|
22
|
+
activeOrganizationId: "active-org",
|
|
23
|
+
activeTeamId: "active-team",
|
|
24
|
+
},
|
|
25
|
+
};
|
|
26
|
+
const user = extractSessionUser(sessionData);
|
|
27
|
+
expect(user).not.toBeNull();
|
|
28
|
+
expect(user?.id).toBe("user-123");
|
|
29
|
+
expect(user?.email).toBe("test@example.com");
|
|
30
|
+
expect(user?.name).toBe("Test User");
|
|
31
|
+
expect(user?.emailVerified).toBe(true);
|
|
32
|
+
expect(user?.image).toBe("https://example.com/avatar.png");
|
|
33
|
+
expect(user?.activeOrganizationId).toBe("active-org");
|
|
34
|
+
expect(user?.activeTeamId).toBe("active-team");
|
|
35
|
+
expect(user?.inherentOrganizationId).toBe("org-123");
|
|
36
|
+
expect(user?.inherentTeamId).toBe("team-123");
|
|
37
|
+
expect(user?.metadata).toEqual({ theme: "dark" });
|
|
38
|
+
});
|
|
39
|
+
it("应该处理最小的用户数据", () => {
|
|
40
|
+
const sessionData = {
|
|
41
|
+
user: {
|
|
42
|
+
id: "user-123",
|
|
43
|
+
email: "test@example.com",
|
|
44
|
+
},
|
|
45
|
+
};
|
|
46
|
+
const user = extractSessionUser(sessionData);
|
|
47
|
+
expect(user).not.toBeNull();
|
|
48
|
+
expect(user?.id).toBe("user-123");
|
|
49
|
+
expect(user?.email).toBe("test@example.com");
|
|
50
|
+
expect(user?.name).toBe("");
|
|
51
|
+
expect(user?.emailVerified).toBe(false);
|
|
52
|
+
});
|
|
53
|
+
it("应该返回 null 当 user 不存在", () => {
|
|
54
|
+
expect(extractSessionUser(null)).toBeNull();
|
|
55
|
+
expect(extractSessionUser(undefined)).toBeNull();
|
|
56
|
+
expect(extractSessionUser({})).toBeNull();
|
|
57
|
+
expect(extractSessionUser({ user: null })).toBeNull();
|
|
58
|
+
});
|
|
59
|
+
it("应该返回 null 当缺少必需字段", () => {
|
|
60
|
+
expect(extractSessionUser({ user: { id: "123" } })).toBeNull();
|
|
61
|
+
expect(extractSessionUser({ user: { email: "test@example.com" } })).toBeNull();
|
|
62
|
+
});
|
|
63
|
+
it("应该处理字符串格式的日期", () => {
|
|
64
|
+
const sessionData = {
|
|
65
|
+
user: {
|
|
66
|
+
id: "user-123",
|
|
67
|
+
email: "test@example.com",
|
|
68
|
+
createdAt: "2024-01-01T00:00:00.000Z",
|
|
69
|
+
updatedAt: "2024-01-02T00:00:00.000Z",
|
|
70
|
+
},
|
|
71
|
+
};
|
|
72
|
+
const user = extractSessionUser(sessionData);
|
|
73
|
+
expect(user?.createdAt).toBe("2024-01-01T00:00:00.000Z");
|
|
74
|
+
expect(user?.updatedAt).toBe("2024-01-02T00:00:00.000Z");
|
|
75
|
+
});
|
|
76
|
+
});
|
package/dist/api/auth-api.d.ts
CHANGED
|
@@ -1,28 +1,112 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* 认证 API
|
|
3
|
+
*
|
|
4
|
+
* 所有认证相关的 HTTP 请求
|
|
5
|
+
* 统一使用 apiClient 发送请求
|
|
3
6
|
*/
|
|
4
|
-
import type { MagicLinkRequest,
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
|
|
7
|
+
import type { Account, MagicLinkRequest, OAuthAccountInfo, RevokeSessionRequest, SessionUser, UpdateUserRequest, UserSession } from "../types";
|
|
8
|
+
import type { ApiClient } from "./client";
|
|
9
|
+
/**
|
|
10
|
+
* 创建认证 API
|
|
11
|
+
*
|
|
12
|
+
* @param apiClient - API 客户端实例
|
|
13
|
+
*/
|
|
14
|
+
export declare function createAuthApi(apiClient: ApiClient): {
|
|
15
|
+
/**
|
|
16
|
+
* 获取当前 session
|
|
17
|
+
* 使用 tokenStorage 中的 token
|
|
18
|
+
*/
|
|
19
|
+
getSession(): Promise<SessionUser | null>;
|
|
20
|
+
/**
|
|
21
|
+
* 使用指定 token 获取 session
|
|
22
|
+
* 用于 OAuth 回调等场景
|
|
23
|
+
*/
|
|
8
24
|
getSessionWithToken(token: string): Promise<SessionUser | null>;
|
|
9
|
-
|
|
10
|
-
|
|
25
|
+
/**
|
|
26
|
+
* 用户 Onboard
|
|
27
|
+
* 创建默认的伴生组织和团队
|
|
28
|
+
*/
|
|
11
29
|
onboard(token: string): Promise<void>;
|
|
30
|
+
/**
|
|
31
|
+
* 更新用户信息
|
|
32
|
+
*/
|
|
12
33
|
updateUser(data: UpdateUserRequest): Promise<SessionUser | null>;
|
|
34
|
+
/**
|
|
35
|
+
* 发送 Magic Link
|
|
36
|
+
*/
|
|
13
37
|
sendMagicLink(params: MagicLinkRequest): Promise<{
|
|
14
38
|
status: boolean;
|
|
15
39
|
}>;
|
|
40
|
+
/**
|
|
41
|
+
* 重新发送验证邮件
|
|
42
|
+
*/
|
|
43
|
+
resendVerificationEmail(email: string, callbackURL?: string): Promise<{
|
|
44
|
+
status: boolean;
|
|
45
|
+
}>;
|
|
46
|
+
/**
|
|
47
|
+
* 检查邮箱是否已被注册
|
|
48
|
+
*
|
|
49
|
+
* @returns true 表示邮箱已被注册,false 表示可用
|
|
50
|
+
*/
|
|
51
|
+
checkEmailExists(email: string): Promise<boolean>;
|
|
16
52
|
/**
|
|
17
53
|
* 为已登录用户绑定密码
|
|
18
54
|
* 用于通过 OAuth 或 Magic Link 登录的用户设置密码
|
|
19
55
|
*/
|
|
20
56
|
linkCredential(newPassword: string, token?: string): Promise<void>;
|
|
21
57
|
/**
|
|
22
|
-
*
|
|
23
|
-
* 注意:此 API 可能不存在,调用时需要处理错误
|
|
58
|
+
* 更改密码
|
|
24
59
|
*/
|
|
25
|
-
|
|
60
|
+
changePassword(currentPassword: string, newPassword: string, token?: string): Promise<{
|
|
61
|
+
success: boolean;
|
|
62
|
+
}>;
|
|
63
|
+
/**
|
|
64
|
+
* 更改邮箱
|
|
65
|
+
*/
|
|
66
|
+
changeEmail(newEmail: string, callbackURL?: string, token?: string): Promise<{
|
|
67
|
+
success: boolean;
|
|
68
|
+
}>;
|
|
69
|
+
/**
|
|
70
|
+
* 获取用户关联的所有账户
|
|
71
|
+
*
|
|
72
|
+
* 返回用户通过不同方式登录的账户列表
|
|
73
|
+
* - credential: 邮箱密码登录
|
|
74
|
+
* - github: GitHub OAuth 登录
|
|
75
|
+
* - 其他 OAuth 提供商
|
|
76
|
+
*/
|
|
77
|
+
listAccounts(token?: string): Promise<Account[]>;
|
|
78
|
+
/**
|
|
79
|
+
* 获取 OAuth 账户详细信息
|
|
80
|
+
*
|
|
81
|
+
* 通过 accountId 获取 OAuth 提供商的用户详细信息
|
|
82
|
+
* 如 GitHub 用户的 email、name、avatar 等
|
|
83
|
+
*/
|
|
84
|
+
getOAuthAccountInfo(accountId: string, token?: string): Promise<OAuthAccountInfo | null>;
|
|
85
|
+
/**
|
|
86
|
+
* 取消关联 OAuth 账户
|
|
87
|
+
*
|
|
88
|
+
* 解除用户与 OAuth 提供商的关联
|
|
89
|
+
*/
|
|
90
|
+
unlinkAccount(providerId: string, accountId?: string, token?: string): Promise<{
|
|
91
|
+
success: boolean;
|
|
92
|
+
}>;
|
|
93
|
+
/**
|
|
94
|
+
* 删除用户账户
|
|
95
|
+
*/
|
|
96
|
+
deleteUser(password?: string, callbackURL?: string, token?: string): Promise<{
|
|
97
|
+
message: string;
|
|
98
|
+
success: boolean;
|
|
99
|
+
}>;
|
|
100
|
+
/**
|
|
101
|
+
* 获取当前用户的所有会话
|
|
102
|
+
*/
|
|
103
|
+
listSessions(token?: string): Promise<UserSession[]>;
|
|
104
|
+
/**
|
|
105
|
+
* 撤销指定会话
|
|
106
|
+
*/
|
|
107
|
+
revokeSession(params: RevokeSessionRequest, token?: string): Promise<{
|
|
108
|
+
success: boolean;
|
|
109
|
+
}>;
|
|
26
110
|
};
|
|
27
111
|
export type AuthApi = ReturnType<typeof createAuthApi>;
|
|
28
112
|
//# sourceMappingURL=auth-api.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auth-api.d.ts","sourceRoot":"","sources":["../../src/api/auth-api.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"auth-api.d.ts","sourceRoot":"","sources":["../../src/api/auth-api.ts"],"names":[],"mappings":"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