diff --git a/eslint.config.js b/eslint.config.js index 5c08d67..9b6a849 100644 --- a/eslint.config.js +++ b/eslint.config.js @@ -21,7 +21,8 @@ export default defineConfig( 'vue/no-duplicate-attr-inheritance': 'off', 'unocss/order-attributify': 'off', '@typescript-eslint/no-unused-vars': 'off', - 'consistent-return': 'off' + 'consistent-return': 'off', + 'no-alert': 'off' } } ); diff --git a/src/components/common/google-auth.vue b/src/components/common/google-auth.vue new file mode 100644 index 0000000..6af3a36 --- /dev/null +++ b/src/components/common/google-auth.vue @@ -0,0 +1,149 @@ + + + + + + + 开启二步验证 + + + + + + 请使用 Google Authenticator 扫描二维码 + + + + + + + 验证并开启 + 取消 + + + + + + + + + + + 二步验证已开启 + + 关闭二步验证 + + + + + + diff --git a/src/layouts/modules/global-header/components/user-avatar.vue b/src/layouts/modules/global-header/components/user-avatar.vue index 59a658a..ad712b3 100644 --- a/src/layouts/modules/global-header/components/user-avatar.vue +++ b/src/layouts/modules/global-header/components/user-avatar.vue @@ -1,10 +1,13 @@ diff --git a/src/service/api/auth.ts b/src/service/api/auth.ts index 9738318..fef68bc 100644 --- a/src/service/api/auth.ts +++ b/src/service/api/auth.ts @@ -1,5 +1,22 @@ +import { createAuthClient } from 'better-auth/client'; +import { twoFactorClient, usernameClient } from 'better-auth/client/plugins'; +import { getToken } from '@/store/modules/auth/shared'; import { request } from '../request'; +const { VITE_SERVICE_BASE_URL } = import.meta.env; + +export const authClient = createAuthClient({ + baseURL: VITE_SERVICE_BASE_URL, + fetchOptions: { + credentials: 'include', + auth: { + type: 'Bearer', + token: () => getToken() + } + }, + plugins: [usernameClient(), twoFactorClient()] +}); + /** * Login * @@ -7,13 +24,9 @@ import { request } from '../request'; * @param password Password */ export function fetchLogin(username: string, password: string) { - return request({ - url: '/auth/sign-in/username', - method: 'post', - data: { - username, - password - } + return authClient.signIn.username({ + username, + password }); } diff --git a/src/store/modules/auth/index.ts b/src/store/modules/auth/index.ts index fd5c79e..b35ca61 100644 --- a/src/store/modules/auth/index.ts +++ b/src/store/modules/auth/index.ts @@ -102,7 +102,7 @@ export const useAuthStore = defineStore(SetupStoreId.Auth, () => { const res = await fetchLogin(userName, password); if (!res.error) { - const pass = await loginByToken(res.response.data); + const pass = await loginByToken(res.data); if (pass) { // Check if the tab needs to be cleared diff --git a/src/typings/api/auth.d.ts b/src/typings/api/auth.d.ts index c3a0f11..87b9eb0 100644 --- a/src/typings/api/auth.d.ts +++ b/src/typings/api/auth.d.ts @@ -16,6 +16,7 @@ declare namespace Api { email: string; roles: string[]; buttons: string[]; + [key: string]: any; } } } diff --git a/src/typings/components.d.ts b/src/typings/components.d.ts index fc17a1b..69cb3db 100644 --- a/src/typings/components.d.ts +++ b/src/typings/components.d.ts @@ -19,6 +19,7 @@ declare module 'vue' { DarkModeContainer: typeof import('./../components/common/dark-mode-container.vue')['default'] ExceptionBase: typeof import('./../components/common/exception-base.vue')['default'] FullScreen: typeof import('./../components/common/full-screen.vue')['default'] + GoogleAuth: typeof import('./../components/common/google-auth.vue')['default'] IconAntDesignEnterOutlined: typeof import('~icons/ant-design/enter-outlined')['default'] IconAntDesignReloadOutlined: typeof import('~icons/ant-design/reload-outlined')['default'] IconAntDesignSettingOutlined: typeof import('~icons/ant-design/setting-outlined')['default'] @@ -114,6 +115,7 @@ declare global { const DarkModeContainer: typeof import('./../components/common/dark-mode-container.vue')['default'] const ExceptionBase: typeof import('./../components/common/exception-base.vue')['default'] const FullScreen: typeof import('./../components/common/full-screen.vue')['default'] + const GoogleAuth: typeof import('./../components/common/google-auth.vue')['default'] const IconAntDesignEnterOutlined: typeof import('~icons/ant-design/enter-outlined')['default'] const IconAntDesignReloadOutlined: typeof import('~icons/ant-design/reload-outlined')['default'] const IconAntDesignSettingOutlined: typeof import('~icons/ant-design/setting-outlined')['default'] diff --git a/src/views/_builtin/login/modules/pwd-login.vue b/src/views/_builtin/login/modules/pwd-login.vue index fbeb771..3736ebc 100644 --- a/src/views/_builtin/login/modules/pwd-login.vue +++ b/src/views/_builtin/login/modules/pwd-login.vue @@ -46,31 +46,6 @@ interface Account { userName: string; password: string; } - -const accounts = computed(() => [ - { - key: 'super', - label: $t('page.login.pwdLogin.superAdmin'), - userName: 'Super', - password: '123456' - }, - { - key: 'admin', - label: $t('page.login.pwdLogin.admin'), - userName: 'Admin', - password: '123456' - }, - { - key: 'user', - label: $t('page.login.pwdLogin.user'), - userName: 'User', - password: '123456' - } -]); - -async function handleAccountLogin(account: Account) { - await authStore.login(account.userName, account.password); -} @@ -96,22 +71,6 @@ async function handleAccountLogin(account: Account) { {{ $t('common.confirm') }} -
请使用 Google Authenticator 扫描二维码