pki登录bug修复
parent
e7f1634003
commit
5d5fe6419c
|
|
@ -10,7 +10,7 @@ import { resetAllStores, useAccessStore, useUserStore } from '@vben/stores';
|
|||
import { notification } from 'ant-design-vue';
|
||||
import { defineStore } from 'pinia';
|
||||
|
||||
import { doLogout, getUserInfoApi, loginApi, seeConnectionClose } from '#/api';
|
||||
import { doLogout, getUserInfoApi, loginApi, seeConnectionClose, pkiLogin } from '#/api';
|
||||
import { $t } from '#/locales';
|
||||
|
||||
import { useDictStore } from './dict';
|
||||
|
|
@ -82,6 +82,50 @@ export const useAuthStore = defineStore('auth', () => {
|
|||
};
|
||||
}
|
||||
|
||||
async function authPKILogin(params: any, onSuccess?: () => Promise<void> | void) {
|
||||
// 异步处理用户登录操作并获取 accessToken
|
||||
let userInfo: null | UserInfo = null;
|
||||
try {
|
||||
loginLoading.value = true;
|
||||
const { access_token } = await pkiLogin(params);
|
||||
|
||||
// 将 accessToken 存储到 accessStore 中
|
||||
accessStore.setAccessToken(access_token);
|
||||
accessStore.setRefreshToken(access_token);
|
||||
|
||||
// 获取用户信息并存储到 accessStore 中
|
||||
userInfo = await fetchUserInfo();
|
||||
/**
|
||||
* 设置用户信息
|
||||
*/
|
||||
userStore.setUserInfo(userInfo);
|
||||
/**
|
||||
* 在这里设置权限
|
||||
*/
|
||||
accessStore.setAccessCodes(userInfo.permissions);
|
||||
|
||||
if (accessStore.loginExpired) {
|
||||
accessStore.setLoginExpired(false);
|
||||
} else {
|
||||
onSuccess ? await onSuccess?.() : await router.push(DEFAULT_HOME_PATH);
|
||||
}
|
||||
|
||||
if (userInfo?.realName) {
|
||||
notification.success({
|
||||
description: `${$t('authentication.loginSuccessDesc')}:${userInfo?.realName}`,
|
||||
duration: 3,
|
||||
message: $t('authentication.loginSuccess'),
|
||||
});
|
||||
}
|
||||
} finally {
|
||||
loginLoading.value = false;
|
||||
}
|
||||
|
||||
return {
|
||||
userInfo,
|
||||
};
|
||||
}
|
||||
|
||||
async function logout(redirect: boolean = true) {
|
||||
try {
|
||||
await seeConnectionClose();
|
||||
|
|
@ -143,6 +187,7 @@ export const useAuthStore = defineStore('auth', () => {
|
|||
return {
|
||||
$reset,
|
||||
authLogin,
|
||||
authPKILogin,
|
||||
fetchUserInfo,
|
||||
loginLoading,
|
||||
logout,
|
||||
|
|
|
|||
|
|
@ -27,8 +27,9 @@
|
|||
"scripts": {
|
||||
"build": "cross-env NODE_OPTIONS=--max-old-space-size=8192 turbo build",
|
||||
"build:analyze": "turbo build:analyze",
|
||||
"build:antd": "pnpm run build --filter=@vben/web-antd",
|
||||
"build:antd": "pnpm run build NODE_OPTIONS=--max-old-space-size=8192 --filter=@vben/web-antd",
|
||||
"build:docker": "./scripts/deploy/build-local-docker-image.sh",
|
||||
"build:antd:fix": "node --max-old-space-size=8192 node_modules/vite/bin/vite.js build --config vite.config.antd.ts",
|
||||
"changeset": "pnpm exec changeset",
|
||||
"check": "pnpm run check:circular && pnpm run check:dep && pnpm run check:type && pnpm check:cspell",
|
||||
"check:circular": "vsh check-circular",
|
||||
|
|
|
|||
Loading…
Reference in New Issue