@pubinfo-pr/module-auth 0.203.1 → 0.203.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/auth.d.ts +9 -0
- package/dist/core.d.ts +43 -25
- package/dist/helper.d.ts +1 -6
- package/dist/index.d.ts +20 -4
- package/dist/index.js +151 -101
- package/dist/interface.d.ts +17 -6
- package/dist/plugins/index.d.ts +1 -0
- package/dist/plugins/two-factor.d.ts +16 -0
- package/dist/plugins.js +27 -0
- package/dist/providers/default-credentials.d.ts +11 -0
- package/dist/providers/default-credentials.js +14 -0
- package/dist/providers/index.d.ts +5 -0
- package/dist/providers/index.js +7 -0
- package/dist/providers.js +6 -0
- package/package.json +11 -3
- package/src/auth.ts +141 -0
- package/src/components/RedirectLogin/index.ts +3 -4
- package/src/core.ts +143 -64
- package/src/helper.ts +1 -15
- package/src/index.ts +23 -75
- package/src/interface.ts +19 -6
- package/src/plugins/index.ts +1 -0
- package/src/plugins/two-factor.ts +49 -0
- package/src/providers/default-credentials.ts +29 -0
- package/src/providers/index.ts +5 -0
- package/dist/context.d.ts +0 -2
- package/src/context.ts +0 -4
package/src/interface.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import type { RouteLocationRaw } from 'vue-router';
|
|
2
|
+
import type { CreateAuthOptions } from './core';
|
|
2
3
|
|
|
3
4
|
export type Recordable = Record<string, any>;
|
|
4
5
|
export type Fn<T = any, K = any> = (params?: Recordable & T) => Promise<K> | K;
|
|
5
6
|
export type FnApi<T = any, R = any> = (params: Recordable & T, baseURL: string) => Promise<R>;
|
|
6
7
|
|
|
7
|
-
export interface AuthOptions {
|
|
8
|
+
export interface AuthOptions<Plugins extends PluginOptions[]> {
|
|
8
9
|
/** 登录后默认重定向至 */
|
|
9
10
|
redirectTo?: RouteLocationRaw | Fn
|
|
10
11
|
|
|
@@ -17,14 +18,26 @@ export interface AuthOptions {
|
|
|
17
18
|
/** 接口的baseURL */
|
|
18
19
|
baseURL: string
|
|
19
20
|
|
|
20
|
-
providers?:
|
|
21
|
+
providers?: CreateAuthOptions<Plugins>['providers']
|
|
22
|
+
plugins?: CreateAuthOptions<Plugins>['plugins']
|
|
21
23
|
}
|
|
22
24
|
|
|
23
|
-
export interface
|
|
24
|
-
/**
|
|
25
|
-
|
|
25
|
+
export interface CreateAuthModule {
|
|
26
|
+
/** 登录后默认重定向至 */
|
|
27
|
+
redirectTo?: RouteLocationRaw | Fn
|
|
28
|
+
|
|
29
|
+
/** 页面配置 */
|
|
30
|
+
pages?: {
|
|
31
|
+
/** 默认登录页 */
|
|
32
|
+
signIn?: RouteLocationRaw
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export interface PluginOptions<Extend = any> {
|
|
37
|
+
/** 唯一值 */
|
|
38
|
+
id: string
|
|
26
39
|
|
|
27
|
-
|
|
40
|
+
extend?: (context: any) => Extend
|
|
28
41
|
}
|
|
29
42
|
|
|
30
43
|
/** 第三方类型 */
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './two-factor';
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import type { RequestInstance } from 'pubinfo-pr';
|
|
2
|
+
import type { Fn, PluginOptions } from '../interface';
|
|
3
|
+
|
|
4
|
+
interface TwoFactorExtend {
|
|
5
|
+
twoFactor: {
|
|
6
|
+
sendOtp: Fn
|
|
7
|
+
verifyOtp: Fn<{ code: string }>
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export interface TwoFactorOptions {
|
|
12
|
+
/** 请求实例 */
|
|
13
|
+
request: RequestInstance
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export function twoFactor(options: TwoFactorOptions): PluginOptions<TwoFactorExtend> {
|
|
17
|
+
const { request } = options;
|
|
18
|
+
|
|
19
|
+
return {
|
|
20
|
+
id: 'two-factor',
|
|
21
|
+
extend() {
|
|
22
|
+
// TODO 通过 context 拿到账号密码登录接口返回的值
|
|
23
|
+
let login2faCode;
|
|
24
|
+
|
|
25
|
+
return {
|
|
26
|
+
twoFactor: {
|
|
27
|
+
sendOtp(payload) {
|
|
28
|
+
return request.Post('/auth/2fa/prepare', {
|
|
29
|
+
fa2Type: 'sms',
|
|
30
|
+
login2faCode,
|
|
31
|
+
...payload,
|
|
32
|
+
});
|
|
33
|
+
},
|
|
34
|
+
|
|
35
|
+
verifyOtp(payload) {
|
|
36
|
+
const { code, ...params } = payload ?? {};
|
|
37
|
+
|
|
38
|
+
return request.Post('/auth/2fa/verify', {
|
|
39
|
+
fa2Type: 'sms',
|
|
40
|
+
login2faCode,
|
|
41
|
+
verifyCode: code,
|
|
42
|
+
...params,
|
|
43
|
+
});
|
|
44
|
+
},
|
|
45
|
+
},
|
|
46
|
+
};
|
|
47
|
+
},
|
|
48
|
+
};
|
|
49
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { ProviderOptions, ProviderUserOptions } from '../interface';
|
|
2
|
+
import { useUserStore } from 'pubinfo-pr';
|
|
3
|
+
|
|
4
|
+
export interface DefaultCredentialsOptions extends ProviderUserOptions {}
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* `默认登录`
|
|
8
|
+
*
|
|
9
|
+
* 底座自带的用户名密码登录
|
|
10
|
+
*
|
|
11
|
+
* 默认优先使用 `/auth/loginNew` 接口,若登录参数不符合则调用 `/auth/login` 接口
|
|
12
|
+
*/
|
|
13
|
+
export default function DefaultCredentials(options?: DefaultCredentialsOptions): ProviderOptions {
|
|
14
|
+
return {
|
|
15
|
+
id: 'default-credentials',
|
|
16
|
+
name: '默认登录',
|
|
17
|
+
type: 'custom',
|
|
18
|
+
signIn: async (params) => {
|
|
19
|
+
const userStore = useUserStore();
|
|
20
|
+
|
|
21
|
+
// 兼容 `2.1.x` 之前的版本
|
|
22
|
+
// 根据 `captchaType` 字段判断是否使用 `/auth/loginNew` 登录接口
|
|
23
|
+
const signIn = params.captchaType ? userStore.signIn : userStore.login;
|
|
24
|
+
|
|
25
|
+
return await signIn(params);
|
|
26
|
+
},
|
|
27
|
+
...options,
|
|
28
|
+
};
|
|
29
|
+
}
|
package/dist/context.d.ts
DELETED
package/src/context.ts
DELETED