From 220b14be3018bcfa9173273552cf088a32ec259c Mon Sep 17 00:00:00 2001 From: Seven Date: Tue, 20 Jan 2026 06:29:19 +0700 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=E8=B0=B7=E6=AD=8C?= =?UTF-8?q?=E4=BA=8C=E6=AD=A5=E9=AA=8C=E8=AF=81=E5=8A=9F=E8=83=BD=EF=BC=8C?= =?UTF-8?q?=E6=9B=B4=E6=96=B0=E7=94=A8=E6=88=B7=E5=A4=B4=E5=83=8F=E4=B8=8B?= =?UTF-8?q?=E6=8B=89=E8=8F=9C=E5=8D=95=E4=BB=A5=E6=94=AF=E6=8C=81=E9=AA=8C?= =?UTF-8?q?=E8=AF=81=E6=93=8D=E4=BD=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- eslint.config.js | 3 +- src/components/common/google-auth.vue | 149 ++++++++++++++++++ .../global-header/components/user-avatar.vue | 46 +++++- src/service/api/auth.ts | 27 +++- src/store/modules/auth/index.ts | 2 +- src/typings/api/auth.d.ts | 1 + src/typings/components.d.ts | 2 + .../_builtin/login/modules/pwd-login.vue | 41 ----- 8 files changed, 214 insertions(+), 57 deletions(-) create mode 100644 src/components/common/google-auth.vue 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 @@ + + + + + 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); -}