From 64b8619bca0446192eb201a6a9ab0d910cbb3ac0 Mon Sep 17 00:00:00 2001 From: Ryan Wang Date: Tue, 19 Jul 2022 14:56:30 +0800 Subject: [PATCH] fix: the issue of redirection after login Signed-off-by: Ryan Wang --- src/modules/system/users/Login.vue | 30 +++++++++++++----------------- 1 file changed, 13 insertions(+), 17 deletions(-) diff --git a/src/modules/system/users/Login.vue b/src/modules/system/users/Login.vue index 20a1a864c..23ee06e45 100644 --- a/src/modules/system/users/Login.vue +++ b/src/modules/system/users/Login.vue @@ -5,16 +5,11 @@ import { VButton, } from "@halo-dev/components"; import { v4 as uuid } from "uuid"; -import axios from "axios"; import qs from "qs"; import logo from "../../../assets/logo.svg"; import { onMounted, ref } from "vue"; import { submitForm } from "@formkit/vue"; - -const axiosInstance = axios.create({ - baseURL: "http://localhost:8090", - withCredentials: true, -}); +import router from "@/router"; interface LoginForm { _csrf: string; @@ -31,7 +26,7 @@ const loginForm = ref({ logging: false, state: { _csrf: "", - username: "admin", + username: "ryanwang", password: "12345678", }, }); @@ -46,19 +41,20 @@ const handleLogin = async () => { try { loginForm.value.logging = true; - await axiosInstance.post( - `http://localhost:8090/login`, - qs.stringify(loginForm.value.state), - { - headers: { - "Content-Type": "application/x-www-form-urlencoded", - }, - } - ); + await fetch("http://localhost:8090/login", { + method: "POST", + headers: { + "Content-Type": "application/x-www-form-urlencoded", + }, + credentials: "include", + redirect: "manual", + body: qs.stringify(loginForm.value.state), + }); + await router.push({ name: "Dashboard" }); + await router.go(0); } catch (e) { console.error(e); } finally { - window.location.href = "/#/dashboard"; loginForm.value.logging = false; } };