fix: the issue of redirection after login

Signed-off-by: Ryan Wang <i@ryanc.cc>
pull/588/head^2
Ryan Wang 2022-07-19 14:56:30 +08:00
parent da23dcfde1
commit cd317a9bed
1 changed files with 13 additions and 17 deletions

View File

@ -5,16 +5,11 @@ import {
VButton, VButton,
} from "@halo-dev/components"; } from "@halo-dev/components";
import { v4 as uuid } from "uuid"; import { v4 as uuid } from "uuid";
import axios from "axios";
import qs from "qs"; import qs from "qs";
import logo from "../../../assets/logo.svg"; import logo from "../../../assets/logo.svg";
import { onMounted, ref } from "vue"; import { onMounted, ref } from "vue";
import { submitForm } from "@formkit/vue"; import { submitForm } from "@formkit/vue";
import router from "@/router";
const axiosInstance = axios.create({
baseURL: "http://localhost:8090",
withCredentials: true,
});
interface LoginForm { interface LoginForm {
_csrf: string; _csrf: string;
@ -31,7 +26,7 @@ const loginForm = ref<LoginFormState>({
logging: false, logging: false,
state: { state: {
_csrf: "", _csrf: "",
username: "admin", username: "ryanwang",
password: "12345678", password: "12345678",
}, },
}); });
@ -46,19 +41,20 @@ const handleLogin = async () => {
try { try {
loginForm.value.logging = true; loginForm.value.logging = true;
await axiosInstance.post( await fetch("http://localhost:8090/login", {
`http://localhost:8090/login`, method: "POST",
qs.stringify(loginForm.value.state), headers: {
{ "Content-Type": "application/x-www-form-urlencoded",
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) { } catch (e) {
console.error(e); console.error(e);
} finally { } finally {
window.location.href = "/#/dashboard";
loginForm.value.logging = false; loginForm.value.logging = false;
} }
}; };