From 731470934d8057b62028a7cd5ad81b29bbd3ada1 Mon Sep 17 00:00:00 2001 From: Rewrite0 <49576640+Rewrite0@users.noreply.github.com> Date: Thu, 25 May 2023 00:18:10 +0800 Subject: [PATCH] feat: login --- src/api/auth.ts | 20 +++++++++----------- src/hooks/auth.ts | 2 +- src/pages/index.vue | 7 ++++++- src/pages/index/bangumi.vue | 2 +- src/pages/index/config.vue | 2 +- src/pages/login.vue | 1 + src/router-type.d.ts | 2 +- src/router/index.ts | 10 ++++++++++ src/views/ab-sidebar.vue | 2 +- 9 files changed, 31 insertions(+), 17 deletions(-) diff --git a/src/api/auth.ts b/src/api/auth.ts index 2f9e18c4..14fce3aa 100644 --- a/src/api/auth.ts +++ b/src/api/auth.ts @@ -3,18 +3,16 @@ import type { Auth, Logout, Update } from '#/auth'; export const apiAuth = { async login(username: string, password: string) { - const { data } = await axios.post( - 'api/v1/auth/login', - { - username, - password, + const formData = new URLSearchParams({ + username, + password, + }); + + const { data } = await axios.post('api/v1/auth/login', formData, { + headers: { + 'Content-Type': 'application/x-www-form-urlencoded', }, - { - headers: { - 'Content-Type': 'application/x-www-form-urlencoded', - }, - } - ); + }); return data; }, diff --git a/src/hooks/auth.ts b/src/hooks/auth.ts index f36c880b..950a17b7 100644 --- a/src/hooks/auth.ts +++ b/src/hooks/auth.ts @@ -12,7 +12,7 @@ export const useAuth = createSharedComposable(() => { const login = async () => { const res = await apiAuth.login(user.username, user.password); - console.log(res); + token.value = res.access_token; }; const logout = async () => { diff --git a/src/pages/index.vue b/src/pages/index.vue index 7369e7ec..d638a790 100644 --- a/src/pages/index.vue +++ b/src/pages/index.vue @@ -1,4 +1,9 @@ - +