@pubinfo-pr/module-auth 0.203.3 → 0.203.4
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/auth.d.ts +1 -6
- package/dist/context.d.ts +4 -0
- package/dist/deprecated.d.ts +8 -0
- package/dist/index.d.ts +2 -1
- package/dist/index.js +20 -11
- package/package.json +3 -3
- package/src/auth.ts +4 -81
- package/src/components/RedirectLogin/index.ts +5 -3
- package/src/context.ts +14 -0
- package/src/deprecated.ts +85 -0
- package/src/index.ts +3 -2
package/dist/auth.d.ts
CHANGED
|
@@ -1,9 +1,4 @@
|
|
|
1
1
|
import type { ModuleOptions } from 'pubinfo-pr';
|
|
2
2
|
import type { AuthClient as AuthClientInstance } from './core';
|
|
3
|
-
import type {
|
|
4
|
-
export declare const AuthClient: AuthClientInstance;
|
|
5
|
-
/**
|
|
6
|
-
* @deprecated 请使用 `createAuthModule` 和 `createAuth` 替换
|
|
7
|
-
*/
|
|
8
|
-
export declare function auth<Plugins extends PluginOptions[]>(options: AuthOptions<Plugins>): ModuleOptions;
|
|
3
|
+
import type { CreateAuthModule } from './interface';
|
|
9
4
|
export declare function createAuthModule(authClient: AuthClientInstance, options?: CreateAuthModule): ModuleOptions;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { ModuleOptions } from 'pubinfo-pr';
|
|
2
|
+
import type { AuthClient as AuthClientInstance } from './core';
|
|
3
|
+
import type { AuthOptions, PluginOptions } from './interface';
|
|
4
|
+
export declare const AuthClient: AuthClientInstance;
|
|
5
|
+
/**
|
|
6
|
+
* @deprecated 请使用 `createAuthModule` 和 `createAuth` 替换
|
|
7
|
+
*/
|
|
8
|
+
export declare function auth<Plugins extends PluginOptions[]>(options: AuthOptions<Plugins>): ModuleOptions;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
export
|
|
1
|
+
export { createAuthModule } from './auth';
|
|
2
2
|
export { LoginWithFourA } from './components/LoginWithFourA';
|
|
3
3
|
export { createAuth } from './core';
|
|
4
|
+
export { auth } from './deprecated';
|
|
4
5
|
export * from './interface';
|
|
5
6
|
/**
|
|
6
7
|
* @deprecated 认证, 请使用 `authClient.authenticate` 方法替代
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { cleanup, defineIconModule, defineRouteModule, useUserStore } from "pubinfo-pr";
|
|
2
|
-
import { defineComponent, h, onMounted, ref } from "vue";
|
|
2
|
+
import { defineComponent, h, inject, onMounted, ref } from "vue";
|
|
3
3
|
import { useRoute, useRouter } from "vue-router";
|
|
4
4
|
var _virtual_pubinfo_resolver_default = {
|
|
5
5
|
icons: {},
|
|
@@ -71,7 +71,7 @@ const PageAuth = defineComponent({
|
|
|
71
71
|
authenticate: Function
|
|
72
72
|
},
|
|
73
73
|
setup(e) {
|
|
74
|
-
let t = useUserStore(), n = useRoute(), i = useRouter(),
|
|
74
|
+
let t = useUserStore(), n = useRoute(), i = useRouter(), o = ref("授权登录中...");
|
|
75
75
|
return onMounted(async () => {
|
|
76
76
|
let r = await e.authenticate?.(e.type);
|
|
77
77
|
if (r?.success) {
|
|
@@ -82,14 +82,14 @@ const PageAuth = defineComponent({
|
|
|
82
82
|
return;
|
|
83
83
|
}
|
|
84
84
|
e?.redirectTo?.();
|
|
85
|
-
} else
|
|
85
|
+
} else o.value = r?.msg ?? r?.message;
|
|
86
86
|
}), () => h("div", { style: {
|
|
87
87
|
display: "flex",
|
|
88
88
|
justifyContent: "center",
|
|
89
89
|
alignItems: "center",
|
|
90
90
|
width: "100vw",
|
|
91
91
|
height: "100vh"
|
|
92
|
-
} },
|
|
92
|
+
} }, o.value);
|
|
93
93
|
}
|
|
94
94
|
});
|
|
95
95
|
var authClient;
|
|
@@ -137,13 +137,22 @@ function auth(t) {
|
|
|
137
137
|
}
|
|
138
138
|
};
|
|
139
139
|
}
|
|
140
|
+
var key = Symbol("auth");
|
|
141
|
+
function createAuthClientContext(e, t) {
|
|
142
|
+
e.provide(key, t);
|
|
143
|
+
}
|
|
144
|
+
function useAuthClientContext() {
|
|
145
|
+
return inject(key, AuthClient);
|
|
146
|
+
}
|
|
140
147
|
function createAuthModule(t, n = {}) {
|
|
141
148
|
let { redirectTo: r = "/", pages: i = {} } = n, { signIn: a = "/login" } = i;
|
|
142
149
|
return {
|
|
143
150
|
name: "pubinfo-pr:auth",
|
|
144
151
|
enforce: "pre",
|
|
145
152
|
setup(n) {
|
|
146
|
-
let { router: i } = n
|
|
153
|
+
let { router: i, app: o } = n;
|
|
154
|
+
createAuthClientContext(o, t);
|
|
155
|
+
let s = {
|
|
147
156
|
path: "/auth/:type",
|
|
148
157
|
name: "Auth",
|
|
149
158
|
component: PageAuth,
|
|
@@ -164,8 +173,8 @@ function createAuthModule(t, n = {}) {
|
|
|
164
173
|
})
|
|
165
174
|
};
|
|
166
175
|
i.beforeEach((n) => {
|
|
167
|
-
if (!i.hasRoute(
|
|
168
|
-
n.name ===
|
|
176
|
+
if (!i.hasRoute(s.name)) return i.addRoute(s), n.fullPath;
|
|
177
|
+
n.name === s.name && cleanup(), n.path === a && t.redirect();
|
|
169
178
|
});
|
|
170
179
|
}
|
|
171
180
|
};
|
|
@@ -179,7 +188,7 @@ const RedirectLogin = defineComponent({
|
|
|
179
188
|
color: String
|
|
180
189
|
},
|
|
181
190
|
setup(e) {
|
|
182
|
-
let t =
|
|
191
|
+
let t = useAuthClientContext(), n = t.getProvider(e.id);
|
|
183
192
|
return () => h("div", [h("div", { style: { padding: "3rem" } }, h("img", {
|
|
184
193
|
src: e.src,
|
|
185
194
|
class: "w-full"
|
|
@@ -196,8 +205,8 @@ const RedirectLogin = defineComponent({
|
|
|
196
205
|
letterSpacing: "0.1em",
|
|
197
206
|
backgroundColor: e.color
|
|
198
207
|
},
|
|
199
|
-
onClick: () =>
|
|
200
|
-
}, `前往${
|
|
208
|
+
onClick: () => t.signIn(n.id)
|
|
209
|
+
}, `前往${n.name}`)]);
|
|
201
210
|
}
|
|
202
211
|
}), LoginWithFourA = defineComponent({
|
|
203
212
|
name: "LoginWithFourA",
|
|
@@ -215,4 +224,4 @@ const RedirectLogin = defineComponent({
|
|
|
215
224
|
});
|
|
216
225
|
defineRouteModule("auth", _virtual_pubinfo_resolver_default.pages), defineIconModule("auth", _virtual_pubinfo_resolver_default.icons);
|
|
217
226
|
const authenticate = AuthClient.authenticate, redirect = AuthClient.redirect, renderQRCode = AuthClient.renderQRCode, signIn = AuthClient.signIn;
|
|
218
|
-
export {
|
|
227
|
+
export { LoginWithFourA, auth, authenticate, createAuth, createAuthModule, redirect, renderQRCode, signIn };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pubinfo-pr/module-auth",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.203.
|
|
4
|
+
"version": "0.203.4",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": {
|
|
7
7
|
"types": "./dist/index.d.ts",
|
|
@@ -31,10 +31,10 @@
|
|
|
31
31
|
"node": "^20.19.0 || >=22.12.0"
|
|
32
32
|
},
|
|
33
33
|
"peerDependencies": {
|
|
34
|
-
"pubinfo-pr": "0.203.
|
|
34
|
+
"pubinfo-pr": "0.203.4"
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {
|
|
37
|
-
"pubinfo-pr": "0.203.
|
|
37
|
+
"pubinfo-pr": "0.203.4"
|
|
38
38
|
},
|
|
39
39
|
"scripts": {
|
|
40
40
|
"dev": "pubinfo build --watch",
|
package/src/auth.ts
CHANGED
|
@@ -1,89 +1,11 @@
|
|
|
1
1
|
import type { ModuleOptions } from 'pubinfo-pr';
|
|
2
2
|
import type { RouteRecordRaw } from 'vue-router';
|
|
3
3
|
import type { AuthClient as AuthClientInstance } from './core';
|
|
4
|
-
import type {
|
|
4
|
+
import type { CreateAuthModule } from './interface';
|
|
5
5
|
import { cleanup } from 'pubinfo-pr';
|
|
6
|
-
import {
|
|
6
|
+
import { createAuthClientContext } from './context';
|
|
7
7
|
import { PageAuth } from './pages/auth';
|
|
8
8
|
|
|
9
|
-
let authClient!: AuthClientInstance;
|
|
10
|
-
|
|
11
|
-
export const AuthClient: AuthClientInstance = {
|
|
12
|
-
signIn: (...args) => authClient.signIn(...args),
|
|
13
|
-
authenticate: (...args) => authClient.authenticate(...args),
|
|
14
|
-
renderQRCode: (...args) => authClient.renderQRCode(...args),
|
|
15
|
-
redirect: (...args) => authClient.redirect(...args),
|
|
16
|
-
getProvider: (...args) => authClient.getProvider(...args),
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* @deprecated 请使用 `createAuthModule` 和 `createAuth` 替换
|
|
21
|
-
*/
|
|
22
|
-
export function auth<Plugins extends PluginOptions[]>(options: AuthOptions<Plugins>): ModuleOptions {
|
|
23
|
-
const {
|
|
24
|
-
redirectTo = '/',
|
|
25
|
-
pages = {},
|
|
26
|
-
baseURL,
|
|
27
|
-
providers,
|
|
28
|
-
plugins,
|
|
29
|
-
} = options;
|
|
30
|
-
const { signIn = '/login' } = pages;
|
|
31
|
-
|
|
32
|
-
authClient = createAuth<Plugins>({
|
|
33
|
-
baseURL,
|
|
34
|
-
providers,
|
|
35
|
-
plugins,
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
return {
|
|
39
|
-
name: 'pubinfo-pr:auth',
|
|
40
|
-
enforce: 'pre',
|
|
41
|
-
setup(ctx) {
|
|
42
|
-
const { router } = ctx;
|
|
43
|
-
|
|
44
|
-
const ROUTE_AUTH: RouteRecordRaw = {
|
|
45
|
-
path: '/auth/:type',
|
|
46
|
-
name: 'Auth',
|
|
47
|
-
component: PageAuth,
|
|
48
|
-
meta: {
|
|
49
|
-
whiteList: true,
|
|
50
|
-
title: '授权登录',
|
|
51
|
-
},
|
|
52
|
-
props: route => ({
|
|
53
|
-
type: route.params.type,
|
|
54
|
-
authenticate: authClient.authenticate,
|
|
55
|
-
redirectTo() {
|
|
56
|
-
if (typeof redirectTo === 'function') {
|
|
57
|
-
redirectTo();
|
|
58
|
-
return;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
router.push(redirectTo);
|
|
62
|
-
},
|
|
63
|
-
}),
|
|
64
|
-
};
|
|
65
|
-
|
|
66
|
-
router.beforeEach((to) => {
|
|
67
|
-
// 注册静态页面
|
|
68
|
-
if (!router.hasRoute(ROUTE_AUTH.name!)) {
|
|
69
|
-
router.addRoute(ROUTE_AUTH);
|
|
70
|
-
return to.fullPath;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
// 前往单点登录前,清空登录状态
|
|
74
|
-
if (to.name === ROUTE_AUTH.name) {
|
|
75
|
-
cleanup();
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
// 前往登录前,重定向至统一登录页(若有)
|
|
79
|
-
if (to.path === signIn) {
|
|
80
|
-
authClient.redirect();
|
|
81
|
-
}
|
|
82
|
-
});
|
|
83
|
-
},
|
|
84
|
-
};
|
|
85
|
-
}
|
|
86
|
-
|
|
87
9
|
export function createAuthModule(authClient: AuthClientInstance, options: CreateAuthModule = {}): ModuleOptions {
|
|
88
10
|
const {
|
|
89
11
|
redirectTo = '/',
|
|
@@ -95,7 +17,8 @@ export function createAuthModule(authClient: AuthClientInstance, options: Create
|
|
|
95
17
|
name: 'pubinfo-pr:auth',
|
|
96
18
|
enforce: 'pre',
|
|
97
19
|
setup(ctx) {
|
|
98
|
-
const { router } = ctx;
|
|
20
|
+
const { router, app } = ctx;
|
|
21
|
+
createAuthClientContext(app, authClient);
|
|
99
22
|
|
|
100
23
|
const ROUTE_AUTH: RouteRecordRaw = {
|
|
101
24
|
path: '/auth/:type',
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { defineComponent, h } from 'vue';
|
|
2
|
-
import {
|
|
2
|
+
import { useAuthClientContext } from '@/context';
|
|
3
3
|
|
|
4
4
|
export const RedirectLogin = defineComponent({
|
|
5
5
|
name: 'RedirectLogin',
|
|
@@ -9,7 +9,9 @@ export const RedirectLogin = defineComponent({
|
|
|
9
9
|
color: String,
|
|
10
10
|
},
|
|
11
11
|
setup(props) {
|
|
12
|
-
const
|
|
12
|
+
const authClient = useAuthClientContext();
|
|
13
|
+
const provider = authClient.getProvider(props.id);
|
|
14
|
+
|
|
13
15
|
return () => {
|
|
14
16
|
return h('div', [
|
|
15
17
|
h(
|
|
@@ -32,7 +34,7 @@ export const RedirectLogin = defineComponent({
|
|
|
32
34
|
letterSpacing: '0.1em',
|
|
33
35
|
backgroundColor: props.color,
|
|
34
36
|
},
|
|
35
|
-
onClick: () =>
|
|
37
|
+
onClick: () => authClient.signIn(provider.id),
|
|
36
38
|
},
|
|
37
39
|
`前往${provider.name}`,
|
|
38
40
|
),
|
package/src/context.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { App } from 'vue';
|
|
2
|
+
import type { AuthClient as AuthClientInstance } from './core';
|
|
3
|
+
import { inject } from 'vue';
|
|
4
|
+
import { AuthClient } from './deprecated';
|
|
5
|
+
|
|
6
|
+
const key = Symbol('auth');
|
|
7
|
+
|
|
8
|
+
export function createAuthClientContext(app: App, authClient: AuthClientInstance) {
|
|
9
|
+
app.provide(key, authClient);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export function useAuthClientContext() {
|
|
13
|
+
return inject(key, AuthClient) as AuthClientInstance;
|
|
14
|
+
}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import type { ModuleOptions } from 'pubinfo-pr';
|
|
2
|
+
import type { RouteRecordRaw } from 'vue-router';
|
|
3
|
+
import type { AuthClient as AuthClientInstance } from './core';
|
|
4
|
+
import type { AuthOptions, PluginOptions } from './interface';
|
|
5
|
+
import { cleanup } from 'pubinfo-pr';
|
|
6
|
+
import { createAuth } from './core';
|
|
7
|
+
import { PageAuth } from './pages/auth';
|
|
8
|
+
|
|
9
|
+
let authClient!: AuthClientInstance;
|
|
10
|
+
|
|
11
|
+
export const AuthClient: AuthClientInstance = {
|
|
12
|
+
signIn: (...args) => authClient.signIn(...args),
|
|
13
|
+
authenticate: (...args) => authClient.authenticate(...args),
|
|
14
|
+
renderQRCode: (...args) => authClient.renderQRCode(...args),
|
|
15
|
+
redirect: (...args) => authClient.redirect(...args),
|
|
16
|
+
getProvider: (...args) => authClient.getProvider(...args),
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* @deprecated 请使用 `createAuthModule` 和 `createAuth` 替换
|
|
21
|
+
*/
|
|
22
|
+
export function auth<Plugins extends PluginOptions[]>(options: AuthOptions<Plugins>): ModuleOptions {
|
|
23
|
+
const {
|
|
24
|
+
redirectTo = '/',
|
|
25
|
+
pages = {},
|
|
26
|
+
baseURL,
|
|
27
|
+
providers,
|
|
28
|
+
plugins,
|
|
29
|
+
} = options;
|
|
30
|
+
const { signIn = '/login' } = pages;
|
|
31
|
+
|
|
32
|
+
authClient = createAuth<Plugins>({
|
|
33
|
+
baseURL,
|
|
34
|
+
providers,
|
|
35
|
+
plugins,
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
return {
|
|
39
|
+
name: 'pubinfo-pr:auth',
|
|
40
|
+
enforce: 'pre',
|
|
41
|
+
setup(ctx) {
|
|
42
|
+
const { router } = ctx;
|
|
43
|
+
|
|
44
|
+
const ROUTE_AUTH: RouteRecordRaw = {
|
|
45
|
+
path: '/auth/:type',
|
|
46
|
+
name: 'Auth',
|
|
47
|
+
component: PageAuth,
|
|
48
|
+
meta: {
|
|
49
|
+
whiteList: true,
|
|
50
|
+
title: '授权登录',
|
|
51
|
+
},
|
|
52
|
+
props: route => ({
|
|
53
|
+
type: route.params.type,
|
|
54
|
+
authenticate: authClient.authenticate,
|
|
55
|
+
redirectTo() {
|
|
56
|
+
if (typeof redirectTo === 'function') {
|
|
57
|
+
redirectTo();
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
router.push(redirectTo);
|
|
62
|
+
},
|
|
63
|
+
}),
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
router.beforeEach((to) => {
|
|
67
|
+
// 注册静态页面
|
|
68
|
+
if (!router.hasRoute(ROUTE_AUTH.name!)) {
|
|
69
|
+
router.addRoute(ROUTE_AUTH);
|
|
70
|
+
return to.fullPath;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
// 前往单点登录前,清空登录状态
|
|
74
|
+
if (to.name === ROUTE_AUTH.name) {
|
|
75
|
+
cleanup();
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
// 前往登录前,重定向至统一登录页(若有)
|
|
79
|
+
if (to.path === signIn) {
|
|
80
|
+
authClient.redirect();
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
},
|
|
84
|
+
};
|
|
85
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import { AuthClient } from './
|
|
1
|
+
import { AuthClient } from './deprecated';
|
|
2
2
|
|
|
3
|
-
export
|
|
3
|
+
export { createAuthModule } from './auth';
|
|
4
4
|
export { LoginWithFourA } from './components/LoginWithFourA';
|
|
5
5
|
export { createAuth } from './core';
|
|
6
|
+
export { auth } from './deprecated';
|
|
6
7
|
export * from './interface';
|
|
7
8
|
|
|
8
9
|
/**
|