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 @@ - +