@pubinfo/module-auth 2.0.0-beta.15 → 2.0.0-beta.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/dist/index.d.ts +15 -10
- package/dist/index.js +76 -102
- package/dist/{interface-C_qnbvmk.d.ts → interface-BStwVrS7.d.ts} +2 -2
- package/dist/providers/4A.d.ts +1 -1
- package/dist/providers/credentials.d.ts +1 -1
- package/dist/providers/ding-zj.d.ts +1 -1
- package/package.json +3 -3
- package/src/core.ts +0 -1
- package/src/index.ts +43 -72
- package/src/interface.ts +1 -1
- package/src/pages/auth.ts +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,33 +1,38 @@
|
|
|
1
|
-
import { A as AuthOptions, T as ThirdParty, R as Recordable } from './interface-C_qnbvmk.js';
|
|
2
|
-
export { b as AuthConfig, d as Authorization, F as Fn, a as FnApi, c as ProviderConfig, P as ProviderUserConfig } from './interface-C_qnbvmk.js';
|
|
3
1
|
import { ModuleOptions } from 'pubinfo';
|
|
2
|
+
import { A as AuthConfig, T as ThirdParty, R as Recordable, a as AuthOptions } from './interface-BStwVrS7.js';
|
|
3
|
+
export { d as Authorization, F as Fn, b as FnApi, c as ProviderConfig, P as ProviderUserConfig } from './interface-BStwVrS7.js';
|
|
4
4
|
import 'vue-router';
|
|
5
5
|
|
|
6
|
-
|
|
6
|
+
/**
|
|
7
|
+
* 初始化
|
|
8
|
+
*/
|
|
9
|
+
declare function createAuth(config?: AuthConfig): {
|
|
7
10
|
/**
|
|
8
11
|
* 前往登录
|
|
9
12
|
* @param id 唯一值
|
|
10
13
|
* @param options 登录时需要传递的参数
|
|
11
14
|
*/
|
|
12
|
-
signIn
|
|
15
|
+
signIn(id: ThirdParty, options?: Recordable): Promise<any>;
|
|
13
16
|
/**
|
|
14
17
|
* 生成二维码
|
|
15
18
|
* @param id 第三方的唯一值
|
|
16
19
|
* @param options 生成二维码需要传递的参数
|
|
17
20
|
* @param options.id `getElementById`中指定的`id`
|
|
18
21
|
*/
|
|
19
|
-
renderQRCode
|
|
22
|
+
renderQRCode(id: ThirdParty, options: {
|
|
20
23
|
id: string;
|
|
21
|
-
} & Recordable)
|
|
24
|
+
} & Recordable): void;
|
|
22
25
|
/**
|
|
23
26
|
* 认证
|
|
24
27
|
* @param id 第三方的唯一值
|
|
25
28
|
*/
|
|
26
|
-
authentication
|
|
29
|
+
authentication(id: ThirdParty): Promise<any>;
|
|
27
30
|
/**
|
|
28
|
-
*
|
|
31
|
+
* 重定向至统一登录页
|
|
29
32
|
*/
|
|
30
|
-
|
|
33
|
+
redirect(): void;
|
|
31
34
|
};
|
|
32
35
|
|
|
33
|
-
|
|
36
|
+
declare function withModule(auth: ReturnType<typeof createAuth>, options?: AuthOptions): ModuleOptions;
|
|
37
|
+
|
|
38
|
+
export { AuthConfig, AuthOptions, Recordable, ThirdParty, createAuth, withModule };
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,45 @@
|
|
|
1
1
|
// src/index.ts
|
|
2
2
|
import { cleanup } from "pubinfo";
|
|
3
3
|
|
|
4
|
+
// src/pages/auth.ts
|
|
5
|
+
import { useUserStore } from "pubinfo";
|
|
6
|
+
import { defineComponent, h, onMounted, ref } from "vue";
|
|
7
|
+
var PageAuth = defineComponent({
|
|
8
|
+
props: {
|
|
9
|
+
type: String,
|
|
10
|
+
redirectTo: Function,
|
|
11
|
+
authentication: Function
|
|
12
|
+
},
|
|
13
|
+
setup(props) {
|
|
14
|
+
const userStore = useUserStore();
|
|
15
|
+
const message = ref("\u6388\u6743\u767B\u5F55\u4E2D...");
|
|
16
|
+
onMounted(async () => {
|
|
17
|
+
const res = await props.authentication?.(props.type);
|
|
18
|
+
if (res?.success) {
|
|
19
|
+
userStore.setToken(res?.data?.accessToken, res?.data?.refreshToken);
|
|
20
|
+
props?.redirectTo?.();
|
|
21
|
+
} else {
|
|
22
|
+
message.value = res?.msg ?? res?.message;
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
return () => {
|
|
26
|
+
return h(
|
|
27
|
+
"div",
|
|
28
|
+
{
|
|
29
|
+
style: {
|
|
30
|
+
display: "flex",
|
|
31
|
+
justifyContent: "center",
|
|
32
|
+
alignItems: "center",
|
|
33
|
+
width: "100vw",
|
|
34
|
+
height: "100vh"
|
|
35
|
+
}
|
|
36
|
+
},
|
|
37
|
+
message.value
|
|
38
|
+
);
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
|
|
4
43
|
// src/core.ts
|
|
5
44
|
function createAuth(config = {}) {
|
|
6
45
|
const {
|
|
@@ -85,112 +124,47 @@ function createUrl(provider) {
|
|
|
85
124
|
return `${url.toString()}?${params.toString()}`;
|
|
86
125
|
}
|
|
87
126
|
|
|
88
|
-
// src/pages/auth.ts
|
|
89
|
-
import { useUserStore } from "pubinfo";
|
|
90
|
-
import { defineComponent, h, onMounted, ref } from "vue";
|
|
91
|
-
var Auth = defineComponent({
|
|
92
|
-
props: {
|
|
93
|
-
type: String,
|
|
94
|
-
redirectTo: Function,
|
|
95
|
-
authentication: Function
|
|
96
|
-
},
|
|
97
|
-
setup(props) {
|
|
98
|
-
const userStore = useUserStore();
|
|
99
|
-
const message = ref("\u6388\u6743\u767B\u5F55\u4E2D...");
|
|
100
|
-
onMounted(async () => {
|
|
101
|
-
const res = await props.authentication?.(props.type);
|
|
102
|
-
if (res?.success) {
|
|
103
|
-
userStore.setToken(res?.data?.accessToken, res?.data?.refreshToken);
|
|
104
|
-
props?.redirectTo?.();
|
|
105
|
-
} else {
|
|
106
|
-
message.value = res?.msg ?? res?.message;
|
|
107
|
-
}
|
|
108
|
-
});
|
|
109
|
-
return () => {
|
|
110
|
-
return h(
|
|
111
|
-
"div",
|
|
112
|
-
{
|
|
113
|
-
style: {
|
|
114
|
-
display: "flex",
|
|
115
|
-
justifyContent: "center",
|
|
116
|
-
alignItems: "center",
|
|
117
|
-
width: "100vw",
|
|
118
|
-
height: "100vh"
|
|
119
|
-
}
|
|
120
|
-
},
|
|
121
|
-
message.value
|
|
122
|
-
);
|
|
123
|
-
};
|
|
124
|
-
}
|
|
125
|
-
});
|
|
126
|
-
|
|
127
127
|
// src/index.ts
|
|
128
|
-
function
|
|
128
|
+
function withModule(auth, options = {}) {
|
|
129
|
+
const { authentication, redirect } = auth;
|
|
129
130
|
const { redirectTo } = options;
|
|
130
|
-
const { signIn, renderQRCode, authentication, redirect } = createAuth(options);
|
|
131
|
-
function auth() {
|
|
132
|
-
return {
|
|
133
|
-
name: "pubinfo:auth",
|
|
134
|
-
enforce: "pre",
|
|
135
|
-
setup(ctx) {
|
|
136
|
-
const { router } = ctx;
|
|
137
|
-
const ROUTE_AUTH = {
|
|
138
|
-
path: "/auth/:type",
|
|
139
|
-
name: "Auth",
|
|
140
|
-
component: Auth,
|
|
141
|
-
meta: {
|
|
142
|
-
whiteList: true,
|
|
143
|
-
title: "\u6388\u6743\u767B\u5F55"
|
|
144
|
-
},
|
|
145
|
-
props: (route) => ({
|
|
146
|
-
type: route.params.type,
|
|
147
|
-
redirectTo() {
|
|
148
|
-
router.push(redirectTo ?? "/");
|
|
149
|
-
},
|
|
150
|
-
authentication
|
|
151
|
-
})
|
|
152
|
-
};
|
|
153
|
-
router.beforeEach((to) => {
|
|
154
|
-
if (!router.hasRoute(ROUTE_AUTH.name)) {
|
|
155
|
-
router.addRoute(ROUTE_AUTH);
|
|
156
|
-
return to.fullPath;
|
|
157
|
-
}
|
|
158
|
-
if (to.name === ROUTE_AUTH.name) {
|
|
159
|
-
cleanup();
|
|
160
|
-
}
|
|
161
|
-
if (to.name === "Login") {
|
|
162
|
-
redirect();
|
|
163
|
-
}
|
|
164
|
-
});
|
|
165
|
-
}
|
|
166
|
-
};
|
|
167
|
-
}
|
|
168
|
-
;
|
|
169
131
|
return {
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
132
|
+
name: "pubinfo:auth",
|
|
133
|
+
enforce: "pre",
|
|
134
|
+
setup(ctx) {
|
|
135
|
+
const { router } = ctx;
|
|
136
|
+
const ROUTE_AUTH = {
|
|
137
|
+
path: "/auth/:type",
|
|
138
|
+
name: "Auth",
|
|
139
|
+
component: PageAuth,
|
|
140
|
+
meta: {
|
|
141
|
+
whiteList: true,
|
|
142
|
+
title: "\u6388\u6743\u767B\u5F55"
|
|
143
|
+
},
|
|
144
|
+
props: (route) => ({
|
|
145
|
+
type: route.params.type,
|
|
146
|
+
redirectTo() {
|
|
147
|
+
router.push(redirectTo ?? "/");
|
|
148
|
+
},
|
|
149
|
+
authentication
|
|
150
|
+
})
|
|
151
|
+
};
|
|
152
|
+
router.beforeEach((to) => {
|
|
153
|
+
if (!router.hasRoute(ROUTE_AUTH.name)) {
|
|
154
|
+
router.addRoute(ROUTE_AUTH);
|
|
155
|
+
return to.fullPath;
|
|
156
|
+
}
|
|
157
|
+
if (to.name === ROUTE_AUTH.name) {
|
|
158
|
+
cleanup();
|
|
159
|
+
}
|
|
160
|
+
if (to.name === "Login") {
|
|
161
|
+
redirect();
|
|
162
|
+
}
|
|
163
|
+
});
|
|
164
|
+
}
|
|
192
165
|
};
|
|
193
166
|
}
|
|
194
167
|
export {
|
|
195
|
-
|
|
168
|
+
createAuth,
|
|
169
|
+
withModule
|
|
196
170
|
};
|
|
@@ -3,7 +3,7 @@ import { RouteLocationRaw } from 'vue-router';
|
|
|
3
3
|
type Recordable = Record<string, any>;
|
|
4
4
|
type Fn<T = any, K = any> = (params?: Recordable & T) => Promise<K> | K;
|
|
5
5
|
type FnApi<T = any> = (params: Recordable & T, baseURL: string) => Promise<any>;
|
|
6
|
-
interface AuthOptions
|
|
6
|
+
interface AuthOptions {
|
|
7
7
|
/** 登录后重定向至 */
|
|
8
8
|
redirectTo?: RouteLocationRaw;
|
|
9
9
|
}
|
|
@@ -47,4 +47,4 @@ interface Authorization {
|
|
|
47
47
|
params?: Recordable;
|
|
48
48
|
}
|
|
49
49
|
|
|
50
|
-
export type {
|
|
50
|
+
export type { AuthConfig as A, Fn as F, ProviderUserConfig as P, Recordable as R, ThirdParty as T, AuthOptions as a, FnApi as b, ProviderConfig as c, Authorization as d };
|
package/dist/providers/4A.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pubinfo/module-auth",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "2.0.0-beta.
|
|
4
|
+
"version": "2.0.0-beta.16",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": {
|
|
7
7
|
"types": "./dist/index.d.ts",
|
|
@@ -20,11 +20,11 @@
|
|
|
20
20
|
"src"
|
|
21
21
|
],
|
|
22
22
|
"peerDependencies": {
|
|
23
|
-
"pubinfo": "2.0.0-beta.
|
|
23
|
+
"pubinfo": "2.0.0-beta.16"
|
|
24
24
|
},
|
|
25
25
|
"devDependencies": {
|
|
26
26
|
"tsup": "^8.4.0",
|
|
27
|
-
"pubinfo": "2.0.0-beta.
|
|
27
|
+
"pubinfo": "2.0.0-beta.16"
|
|
28
28
|
},
|
|
29
29
|
"scripts": {
|
|
30
30
|
"dev": "tsup --watch src",
|
package/src/core.ts
CHANGED
package/src/index.ts
CHANGED
|
@@ -1,86 +1,57 @@
|
|
|
1
1
|
import type { ModuleOptions } from 'pubinfo';
|
|
2
2
|
import type { RouteRecordRaw } from 'vue-router';
|
|
3
|
+
import type { createAuth } from './core';
|
|
3
4
|
import type { AuthOptions } from './interface';
|
|
4
5
|
import { cleanup } from 'pubinfo';
|
|
5
|
-
import {
|
|
6
|
-
import { Auth } from './pages/auth';
|
|
6
|
+
import { PageAuth } from './pages/auth';
|
|
7
7
|
|
|
8
|
-
export function createAuth
|
|
8
|
+
export function withModule(auth: ReturnType<typeof createAuth>, options: AuthOptions = {}): ModuleOptions {
|
|
9
|
+
const { authentication, redirect } = auth;
|
|
9
10
|
const { redirectTo } = options;
|
|
10
|
-
const { signIn, renderQRCode, authentication, redirect } = create(options);
|
|
11
11
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
12
|
+
return {
|
|
13
|
+
name: 'pubinfo:auth',
|
|
14
|
+
enforce: 'pre',
|
|
15
|
+
setup(ctx) {
|
|
16
|
+
const { router } = ctx;
|
|
17
|
+
|
|
18
|
+
const ROUTE_AUTH: RouteRecordRaw = {
|
|
19
|
+
path: '/auth/:type',
|
|
20
|
+
name: 'Auth',
|
|
21
|
+
component: PageAuth,
|
|
22
|
+
meta: {
|
|
23
|
+
whiteList: true,
|
|
24
|
+
title: '授权登录',
|
|
25
|
+
},
|
|
26
|
+
props: (route) => ({
|
|
27
|
+
type: route.params.type,
|
|
28
|
+
redirectTo() {
|
|
29
|
+
router.push(redirectTo ?? '/');
|
|
26
30
|
},
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
router.push(redirectTo ?? '/');
|
|
31
|
-
},
|
|
32
|
-
authentication,
|
|
33
|
-
}),
|
|
34
|
-
};
|
|
31
|
+
authentication,
|
|
32
|
+
}),
|
|
33
|
+
};
|
|
35
34
|
|
|
36
|
-
|
|
35
|
+
router.beforeEach(to => {
|
|
37
36
|
// 注册静态页面
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
};
|
|
55
|
-
};
|
|
56
|
-
|
|
57
|
-
return {
|
|
58
|
-
/**
|
|
59
|
-
* 前往登录
|
|
60
|
-
* @param id 唯一值
|
|
61
|
-
* @param options 登录时需要传递的参数
|
|
62
|
-
*/
|
|
63
|
-
signIn,
|
|
64
|
-
|
|
65
|
-
/**
|
|
66
|
-
* 生成二维码
|
|
67
|
-
* @param id 第三方的唯一值
|
|
68
|
-
* @param options 生成二维码需要传递的参数
|
|
69
|
-
* @param options.id `getElementById`中指定的`id`
|
|
70
|
-
*/
|
|
71
|
-
renderQRCode,
|
|
72
|
-
|
|
73
|
-
/**
|
|
74
|
-
* 认证
|
|
75
|
-
* @param id 第三方的唯一值
|
|
76
|
-
*/
|
|
77
|
-
authentication,
|
|
78
|
-
|
|
79
|
-
/**
|
|
80
|
-
* 模块配置
|
|
81
|
-
*/
|
|
82
|
-
auth,
|
|
37
|
+
if (!router.hasRoute(ROUTE_AUTH.name!)) {
|
|
38
|
+
router.addRoute(ROUTE_AUTH);
|
|
39
|
+
return to.fullPath;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// 前往单点登录前,清空登录状态
|
|
43
|
+
if (to.name === ROUTE_AUTH.name) {
|
|
44
|
+
cleanup();
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// 前往登录前,重定向至统一登录页(若有)
|
|
48
|
+
if (to.name === 'Login') {
|
|
49
|
+
redirect();
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
},
|
|
83
53
|
};
|
|
84
54
|
}
|
|
85
55
|
|
|
56
|
+
export * from './core';
|
|
86
57
|
export * from './interface';
|
package/src/interface.ts
CHANGED
|
@@ -4,7 +4,7 @@ export type Recordable = Record<string, any>;
|
|
|
4
4
|
export type Fn<T = any, K = any> = (params?: Recordable & T) => Promise<K> | K;
|
|
5
5
|
export type FnApi<T = any> = (params: Recordable & T, baseURL: string) => Promise<any>;
|
|
6
6
|
|
|
7
|
-
export interface AuthOptions
|
|
7
|
+
export interface AuthOptions {
|
|
8
8
|
/** 登录后重定向至 */
|
|
9
9
|
redirectTo?: RouteLocationRaw
|
|
10
10
|
}
|
package/src/pages/auth.ts
CHANGED