@sud-web/utils 0.0.1 → 0.0.2
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/dist/index.d.mts +28 -1
- package/dist/index.mjs +1 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -3,13 +3,40 @@ declare function getCsrfToken(): string | null;
|
|
|
3
3
|
declare function setCsrfToken(token: string): void;
|
|
4
4
|
declare function removeCsrfToken(): void;
|
|
5
5
|
|
|
6
|
+
declare const AUTHKEYNAME = "sud_auth_code";
|
|
7
|
+
|
|
6
8
|
interface IRedirectToLoginParams {
|
|
9
|
+
/** 平台 channel 标识(必填) */
|
|
7
10
|
channel: string;
|
|
11
|
+
/** Auth 系统基础地址,例如:https://auth.example.com */
|
|
8
12
|
authBaseUrl: string;
|
|
13
|
+
/** Auth 系统路由路径,例如:/login */
|
|
9
14
|
authPath?: string;
|
|
15
|
+
/**
|
|
16
|
+
* 登录后回跳地址
|
|
17
|
+
* @default location.href
|
|
18
|
+
*/
|
|
10
19
|
redirect_uri?: string;
|
|
20
|
+
/**
|
|
21
|
+
* 调试模式
|
|
22
|
+
* 开启后不会跳转 location.href
|
|
23
|
+
* @default false
|
|
24
|
+
*/
|
|
11
25
|
debug?: boolean;
|
|
12
26
|
}
|
|
27
|
+
/**
|
|
28
|
+
* 跳转到 Auth 登录页
|
|
29
|
+
*
|
|
30
|
+
* @param props 登录重定向参数
|
|
31
|
+
*
|
|
32
|
+
* - channel: 当前系统平台字符串
|
|
33
|
+
* - authBaseUrl: Auth 地址 统一登录的域名,在env文件中定义,需要传入
|
|
34
|
+
* - authPath: 是否指定跳到统一登录的某一个页面,如"/logout" 主动退出时可填入这个参数
|
|
35
|
+
* - redirect_uri: 登录后回跳地址
|
|
36
|
+
* - debug: 调试模式 开启后不会跳转 location.href
|
|
37
|
+
*
|
|
38
|
+
*
|
|
39
|
+
*/
|
|
13
40
|
declare function redirectToLogin(props?: IRedirectToLoginParams): void;
|
|
14
41
|
|
|
15
|
-
export { getCsrfToken, redirectToLogin, removeCsrfToken, setCsrfToken };
|
|
42
|
+
export { AUTHKEYNAME, getCsrfToken, redirectToLogin, removeCsrfToken, setCsrfToken };
|
package/dist/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var c="sud_auth_code",n=class{static XSRFSTART="x-xsrf-token"},t=n;function d(){return localStorage.getItem(t.XSRFSTART)}function T(r){return localStorage.setItem(t.XSRFSTART,r)}function l(){localStorage.removeItem(t.XSRFSTART);}function x(r={authBaseUrl:"",channel:""}){let{authBaseUrl:a,authPath:u="",redirect_uri:
|
|
1
|
+
var c="sud_auth_code",n=class{static XSRFSTART="x-xsrf-token"},t=n;function d(){return localStorage.getItem(t.XSRFSTART)}function T(r){return localStorage.setItem(t.XSRFSTART,r)}function l(){localStorage.removeItem(t.XSRFSTART);}function x(r={authBaseUrl:"",channel:""}){let{authBaseUrl:a,authPath:u="",redirect_uri:f,debug:h,channel:i}=r;if(!a){console.error("authBaseUrl must be has value");return}if(!i){console.error("channel must be has value");return}let o=f||location.href;if(console.log("[ redirect_uri ] >",o),!o){console.log("[ error ] > no redirect_uri");return}let s=new URL(o);s.searchParams.delete(c),l();let e=new URL(a+u);e.searchParams.append("channel",i),e.searchParams.append("redirect_uri",s.toString()),console.log("[ to.fullPath ] >",e.toString()),h||(location.href=e.toString());}export{c as AUTHKEYNAME,d as getCsrfToken,x as redirectToLogin,l as removeCsrfToken,T as setCsrfToken};
|