@choiceform/shared-auth 0.1.17 → 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 -0
- package/dist/hooks/use-auth-init.d.ts.map +1 -1
- package/dist/hooks/use-auth-init.js +16 -21
- 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
package/dist/types/user.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"user.d.ts","sourceRoot":"","sources":["../../src/types/user.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,kBAAkB;AAClB,MAAM,WAAW,mBAAmB;IAClC,KAAK,CAAC,EAAE,MAAM,CAAA;
|
|
1
|
+
{"version":3,"file":"user.d.ts","sourceRoot":"","sources":["../../src/types/user.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,kBAAkB;AAClB,MAAM,WAAW,mBAAmB;IAClC,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;IACtB,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,WAAW,CAAC,EAAE,MAAM,CAAA;CACrB;AAED,aAAa;AACb,MAAM,WAAW,WAAW;IAC1B,oBAAoB,CAAC,EAAE,MAAM,CAAA;IAC7B,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,MAAM,CAAC,EAAE,OAAO,CAAA;IAChB,SAAS,EAAE,MAAM,CAAA;IACjB,KAAK,EAAE,MAAM,CAAA;IACb,aAAa,EAAE,OAAO,CAAA;IACtB,EAAE,EAAE,MAAM,CAAA;IACV,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,gCAAgC;IAChC,sBAAsB,CAAC,EAAE,MAAM,CAAA;IAC/B,gCAAgC;IAChC,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,kCAAkC;IAClC,eAAe,CAAC,EAAE,MAAM,CAAA;IACxB,QAAQ,EAAE,mBAAmB,CAAA;IAC7B,IAAI,EAAE,MAAM,CAAA;IACZ,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,SAAS,EAAE,MAAM,CAAA;CAClB;AAED,0BAA0B;AAC1B,MAAM,WAAW,OAAO;IACtB,oBAAoB,CAAC,EAAE,MAAM,CAAA;IAC7B,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,SAAS,EAAE,MAAM,CAAA;IACjB,SAAS,EAAE,MAAM,CAAA;IACjB,EAAE,EAAE,MAAM,CAAA;IACV,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,KAAK,EAAE,MAAM,CAAA;IACb,SAAS,EAAE,MAAM,CAAA;IACjB,IAAI,EAAE,WAAW,CAAA;IACjB,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,MAAM,EAAE,MAAM,CAAA;CACf"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 认证工具函数
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* 验证邮箱格式
|
|
6
|
+
*
|
|
7
|
+
* @param email - 要验证的邮箱
|
|
8
|
+
* @returns 如果是有效的邮箱格式返回 true,否则返回 false
|
|
9
|
+
*/
|
|
10
|
+
export declare function isValidEmail(email: string): boolean;
|
|
11
|
+
/**
|
|
12
|
+
* Better Auth 已知错误代码
|
|
13
|
+
*/
|
|
14
|
+
export declare const AUTH_ERROR_CODES: readonly ["PASSWORD_TOO_SHORT", "PASSWORD_TOO_LONG", "INVALID_EMAIL_OR_PASSWORD", "INVALID_EMAIL", "INVALID_PASSWORD", "USER_NOT_FOUND", "USER_ALREADY_EXISTS", "EMAIL_NOT_VERIFIED", "TOO_MANY_REQUESTS", "INVALID_TOKEN", "SESSION_EXPIRED", "UNAUTHORIZED", "FORBIDDEN", "METADATA_IS_REQUIRED"];
|
|
15
|
+
export type AuthErrorCode = (typeof AUTH_ERROR_CODES)[number];
|
|
16
|
+
/**
|
|
17
|
+
* 解析的认证错误结构
|
|
18
|
+
*/
|
|
19
|
+
export interface ParsedAuthError {
|
|
20
|
+
/** 错误代码(如果有) */
|
|
21
|
+
code: AuthErrorCode | null;
|
|
22
|
+
/** 是否是已知的错误代码 */
|
|
23
|
+
isKnownError: boolean;
|
|
24
|
+
/** 原始错误消息 */
|
|
25
|
+
message: string;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* 解析 Better Auth 错误
|
|
29
|
+
*
|
|
30
|
+
* 支持的格式:
|
|
31
|
+
* - JSON: {"code":"PASSWORD_TOO_SHORT","message":"..."}
|
|
32
|
+
* - 纯文本错误消息
|
|
33
|
+
*
|
|
34
|
+
* 注意:此函数只解析错误,不翻译。翻译由项目自行处理。
|
|
35
|
+
*
|
|
36
|
+
* @param error - 错误字符串
|
|
37
|
+
* @returns 解析后的错误结构
|
|
38
|
+
*/
|
|
39
|
+
export declare function parseAuthError(error: string | null): ParsedAuthError;
|
|
40
|
+
/**
|
|
41
|
+
* 检查错误是否是 token 过期
|
|
42
|
+
*/
|
|
43
|
+
export declare function isTokenExpiredError(error: string | ParsedAuthError | null): boolean;
|
|
44
|
+
/**
|
|
45
|
+
* 从用户名生成邮箱本地部分(注册时如果没有提供 name,使用 email 前缀)
|
|
46
|
+
*/
|
|
47
|
+
export declare function getNameFromEmail(email: string): string;
|
|
48
|
+
/**
|
|
49
|
+
* 构建带参数的 URL
|
|
50
|
+
*/
|
|
51
|
+
export declare function buildAuthUrl(basePath: string, params: Record<string, string | undefined | null>): string;
|
|
52
|
+
/**
|
|
53
|
+
* 构建相对路径带参数
|
|
54
|
+
*/
|
|
55
|
+
export declare function buildAuthPath(path: string, params: Record<string, string | undefined | null>): string;
|
|
56
|
+
/**
|
|
57
|
+
* 清除 URL 中的认证相关参数
|
|
58
|
+
*/
|
|
59
|
+
export declare function clearAuthParams(): void;
|
|
60
|
+
//# sourceMappingURL=auth-utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth-utils.d.ts","sourceRoot":"","sources":["../../src/utils/auth-utils.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;;;;GAKG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAGnD;AAED;;GAEG;AACH,eAAO,MAAM,gBAAgB,qSAenB,CAAA;AAEV,MAAM,MAAM,aAAa,GAAG,CAAC,OAAO,gBAAgB,CAAC,CAAC,MAAM,CAAC,CAAA;AAE7D;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B,gBAAgB;IAChB,IAAI,EAAE,aAAa,GAAG,IAAI,CAAA;IAC1B,iBAAiB;IACjB,YAAY,EAAE,OAAO,CAAC;IACtB,aAAa;IACb,OAAO,EAAE,MAAM,CAAA;CAChB;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,GAAG,eAAe,CAsCpE;AAED;;GAEG;AACH,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,MAAM,GAAG,eAAe,GAAG,IAAI,GAAG,OAAO,CAcnF;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAEtD;AAED;;GAEG;AACH,wBAAgB,YAAY,CAC1B,QAAQ,EAAE,MAAM,EAChB,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,GAAG,IAAI,CAAC,GAChD,MAAM,CAUR;AAED;;GAEG;AACH,wBAAgB,aAAa,CAC3B,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,GAAG,IAAI,CAAC,GAChD,MAAM,CAWR;AAED;;GAEG;AACH,wBAAgB,eAAe,IAAI,IAAI,CAiBtC"}
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 认证工具函数
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* 验证邮箱格式
|
|
6
|
+
*
|
|
7
|
+
* @param email - 要验证的邮箱
|
|
8
|
+
* @returns 如果是有效的邮箱格式返回 true,否则返回 false
|
|
9
|
+
*/
|
|
10
|
+
export function isValidEmail(email) {
|
|
11
|
+
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
|
|
12
|
+
return emailRegex.test(email);
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Better Auth 已知错误代码
|
|
16
|
+
*/
|
|
17
|
+
export const AUTH_ERROR_CODES = [
|
|
18
|
+
"PASSWORD_TOO_SHORT",
|
|
19
|
+
"PASSWORD_TOO_LONG",
|
|
20
|
+
"INVALID_EMAIL_OR_PASSWORD",
|
|
21
|
+
"INVALID_EMAIL",
|
|
22
|
+
"INVALID_PASSWORD",
|
|
23
|
+
"USER_NOT_FOUND",
|
|
24
|
+
"USER_ALREADY_EXISTS",
|
|
25
|
+
"EMAIL_NOT_VERIFIED",
|
|
26
|
+
"TOO_MANY_REQUESTS",
|
|
27
|
+
"INVALID_TOKEN",
|
|
28
|
+
"SESSION_EXPIRED",
|
|
29
|
+
"UNAUTHORIZED",
|
|
30
|
+
"FORBIDDEN",
|
|
31
|
+
"METADATA_IS_REQUIRED",
|
|
32
|
+
];
|
|
33
|
+
/**
|
|
34
|
+
* 解析 Better Auth 错误
|
|
35
|
+
*
|
|
36
|
+
* 支持的格式:
|
|
37
|
+
* - JSON: {"code":"PASSWORD_TOO_SHORT","message":"..."}
|
|
38
|
+
* - 纯文本错误消息
|
|
39
|
+
*
|
|
40
|
+
* 注意:此函数只解析错误,不翻译。翻译由项目自行处理。
|
|
41
|
+
*
|
|
42
|
+
* @param error - 错误字符串
|
|
43
|
+
* @returns 解析后的错误结构
|
|
44
|
+
*/
|
|
45
|
+
export function parseAuthError(error) {
|
|
46
|
+
if (!error) {
|
|
47
|
+
return { code: null, message: "", isKnownError: false };
|
|
48
|
+
}
|
|
49
|
+
// 尝试解析 JSON 格式的错误
|
|
50
|
+
try {
|
|
51
|
+
const parsed = JSON.parse(error);
|
|
52
|
+
if (parsed.code && typeof parsed.code === "string") {
|
|
53
|
+
const code = parsed.code;
|
|
54
|
+
const isKnown = AUTH_ERROR_CODES.includes(code);
|
|
55
|
+
return {
|
|
56
|
+
code: isKnown ? code : null,
|
|
57
|
+
message: parsed.message || error,
|
|
58
|
+
isKnownError: isKnown,
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
catch {
|
|
63
|
+
// 不是 JSON 格式
|
|
64
|
+
}
|
|
65
|
+
// 检查错误消息是否包含已知的错误代码
|
|
66
|
+
for (const code of AUTH_ERROR_CODES) {
|
|
67
|
+
if (error.includes(code)) {
|
|
68
|
+
return {
|
|
69
|
+
code,
|
|
70
|
+
message: error,
|
|
71
|
+
isKnownError: true,
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
// 返回原始错误消息
|
|
76
|
+
return {
|
|
77
|
+
code: null,
|
|
78
|
+
message: error,
|
|
79
|
+
isKnownError: false,
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* 检查错误是否是 token 过期
|
|
84
|
+
*/
|
|
85
|
+
export function isTokenExpiredError(error) {
|
|
86
|
+
if (!error)
|
|
87
|
+
return false;
|
|
88
|
+
const parsed = typeof error === "string" ? parseAuthError(error) : error;
|
|
89
|
+
if (parsed.code === "INVALID_TOKEN" || parsed.code === "SESSION_EXPIRED") {
|
|
90
|
+
return true;
|
|
91
|
+
}
|
|
92
|
+
if (parsed.message.includes("expired")) {
|
|
93
|
+
return true;
|
|
94
|
+
}
|
|
95
|
+
return false;
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* 从用户名生成邮箱本地部分(注册时如果没有提供 name,使用 email 前缀)
|
|
99
|
+
*/
|
|
100
|
+
export function getNameFromEmail(email) {
|
|
101
|
+
return email.split("@")[0] || "";
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* 构建带参数的 URL
|
|
105
|
+
*/
|
|
106
|
+
export function buildAuthUrl(basePath, params) {
|
|
107
|
+
const url = new URL(basePath, window.location.origin);
|
|
108
|
+
for (const [key, value] of Object.entries(params)) {
|
|
109
|
+
if (value !== undefined && value !== null) {
|
|
110
|
+
url.searchParams.set(key, value);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
return url.toString();
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* 构建相对路径带参数
|
|
117
|
+
*/
|
|
118
|
+
export function buildAuthPath(path, params) {
|
|
119
|
+
const searchParams = new URLSearchParams();
|
|
120
|
+
for (const [key, value] of Object.entries(params)) {
|
|
121
|
+
if (value !== undefined && value !== null) {
|
|
122
|
+
searchParams.set(key, value);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
const queryString = searchParams.toString();
|
|
126
|
+
return queryString ? `${path}?${queryString}` : path;
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* 清除 URL 中的认证相关参数
|
|
130
|
+
*/
|
|
131
|
+
export function clearAuthParams() {
|
|
132
|
+
if (typeof window === "undefined")
|
|
133
|
+
return;
|
|
134
|
+
const url = new URL(window.location.href);
|
|
135
|
+
const paramsToRemove = ["token", "isNew", "type", "error"];
|
|
136
|
+
let hasChanges = false;
|
|
137
|
+
for (const param of paramsToRemove) {
|
|
138
|
+
if (url.searchParams.has(param)) {
|
|
139
|
+
url.searchParams.delete(param);
|
|
140
|
+
hasChanges = true;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
if (hasChanges) {
|
|
144
|
+
window.history.replaceState({}, "", url.pathname + url.search);
|
|
145
|
+
}
|
|
146
|
+
}
|
package/dist/utils/index.d.ts
CHANGED
|
@@ -4,4 +4,5 @@
|
|
|
4
4
|
export { toISOString } from "./date";
|
|
5
5
|
export { isDev, getEnvVar, getAuthBaseUrl } from "./env";
|
|
6
6
|
export { extractSessionUser } from "./user-mapper";
|
|
7
|
+
export { isValidEmail, parseAuthError, isTokenExpiredError, getNameFromEmail, buildAuthUrl, buildAuthPath, clearAuthParams, AUTH_ERROR_CODES, type AuthErrorCode, type ParsedAuthError, } from "./auth-utils";
|
|
7
8
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,WAAW,EAAE,MAAM,QAAQ,CAAA;AACpC,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,cAAc,EAAE,MAAM,OAAO,CAAA;AACxD,OAAO,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,WAAW,EAAE,MAAM,QAAQ,CAAA;AACpC,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,cAAc,EAAE,MAAM,OAAO,CAAA;AACxD,OAAO,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAA;AAClD,OAAO,EACL,YAAY,EACZ,cAAc,EACd,mBAAmB,EACnB,gBAAgB,EAChB,YAAY,EACZ,aAAa,EACb,eAAe,EACf,gBAAgB,EAChB,KAAK,aAAa,EAClB,KAAK,eAAe,GACrB,MAAM,cAAc,CAAA"}
|
package/dist/utils/index.js
CHANGED
|
@@ -4,3 +4,4 @@
|
|
|
4
4
|
export { toISOString } from "./date";
|
|
5
5
|
export { isDev, getEnvVar, getAuthBaseUrl } from "./env";
|
|
6
6
|
export { extractSessionUser } from "./user-mapper";
|
|
7
|
+
export { isValidEmail, parseAuthError, isTokenExpiredError, getNameFromEmail, buildAuthUrl, buildAuthPath, clearAuthParams, AUTH_ERROR_CODES, } from "./auth-utils";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"user-mapper.d.ts","sourceRoot":"","sources":["../../src/utils/user-mapper.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAuB,MAAM,UAAU,CAAA;AAEhE;;;;;;;;;;GAUG;AACH,wBAAgB,kBAAkB,CAAC,YAAY,EAAE,OAAO,GAAG,WAAW,GAAG,IAAI,
|
|
1
|
+
{"version":3,"file":"user-mapper.d.ts","sourceRoot":"","sources":["../../src/utils/user-mapper.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAuB,MAAM,UAAU,CAAA;AAEhE;;;;;;;;;;GAUG;AACH,wBAAgB,kBAAkB,CAAC,YAAY,EAAE,OAAO,GAAG,WAAW,GAAG,IAAI,CA0C5E"}
|
|
@@ -47,7 +47,8 @@ export function extractSessionUser(responseData) {
|
|
|
47
47
|
inherentOrganizationId: user.inherentOrganizationId,
|
|
48
48
|
inherentTeamId: user.inherentTeamId,
|
|
49
49
|
lastLoginAt: session?.createdAt ? String(session.createdAt) : undefined,
|
|
50
|
-
|
|
50
|
+
lastLoginMethod: user.lastLoginMethod,
|
|
51
|
+
metadata: user.metadata ?? {},
|
|
51
52
|
name: user.name ?? "",
|
|
52
53
|
role: user.role,
|
|
53
54
|
updatedAt: String(user.updatedAt ?? ""),
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@choiceform/shared-auth",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.18",
|
|
4
4
|
"description": "Shared authentication package for Choiceform projects",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -20,6 +20,8 @@
|
|
|
20
20
|
"build": "tsc",
|
|
21
21
|
"dev": "tsc --watch",
|
|
22
22
|
"clean": "rimraf dist",
|
|
23
|
+
"test": "vitest run",
|
|
24
|
+
"test:watch": "vitest",
|
|
23
25
|
"prepublishOnly": "pnpm run build"
|
|
24
26
|
},
|
|
25
27
|
"repository": {
|
|
@@ -51,9 +53,15 @@
|
|
|
51
53
|
"react-dom": ">=18.0.0"
|
|
52
54
|
},
|
|
53
55
|
"devDependencies": {
|
|
56
|
+
"@legendapp/state": "v3.0.0-beta.26",
|
|
57
|
+
"@testing-library/react": "^16.3.0",
|
|
54
58
|
"@types/react": "18.2.71",
|
|
55
59
|
"@types/react-dom": "18.2.22",
|
|
60
|
+
"happy-dom": "^18.0.1",
|
|
61
|
+
"react": "18.2.0",
|
|
62
|
+
"react-dom": "18.2.0",
|
|
63
|
+
"rimraf": "^6.0.1",
|
|
56
64
|
"typescript": "^5.5.3",
|
|
57
|
-
"
|
|
65
|
+
"vitest": "^3.2.4"
|
|
58
66
|
}
|
|
59
67
|
}
|