From a3b98bf44b484b5b47870ee8ec9b758038887f8a Mon Sep 17 00:00:00 2001 From: RockChinQ <1010553892@qq.com> Date: Fri, 10 May 2024 22:04:26 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20cookies=E6=97=A0=E6=B3=95=E7=94=B1js?= =?UTF-8?q?=E4=BF=AE=E6=94=B9=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/controller/accapi.go | 10 +++++++--- frontend/config.json | 3 --- frontend/src/main.js | 25 +++++++++++++++---------- 3 files changed, 22 insertions(+), 16 deletions(-) delete mode 100644 frontend/config.json diff --git a/backend/controller/accapi.go b/backend/controller/accapi.go index 43deac4..ce45deb 100644 --- a/backend/controller/accapi.go +++ b/backend/controller/accapi.go @@ -81,14 +81,18 @@ func (ar *AccountRouter) LoginAccount(c *gin.Context) { domain := c.Request.Header.Get("Origin") // set-cookie + // 要求: + // 1. 调试模式时允许跨域 + // 2. 设置的域为请求的域 + // 3. 允许js修改 if gin.Mode() == gin.DebugMode { http.SetCookie(c.Writer, &http.Cookie{ Name: "access-token", Value: token, Path: "/", Domain: domain, - Secure: true, - SameSite: http.SameSiteNoneMode, + Secure: false, + SameSite: http.SameSiteLaxMode, HttpOnly: false, MaxAge: 3600, }) @@ -99,7 +103,7 @@ func (ar *AccountRouter) LoginAccount(c *gin.Context) { Value: token, Path: "/", Domain: domain, - Secure: true, + Secure: false, SameSite: http.SameSiteStrictMode, HttpOnly: false, MaxAge: 3600, diff --git a/frontend/config.json b/frontend/config.json deleted file mode 100644 index 24ad9eb..0000000 --- a/frontend/config.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "base_url": "" -} \ No newline at end of file diff --git a/frontend/src/main.js b/frontend/src/main.js index 7f336eb..c849848 100644 --- a/frontend/src/main.js +++ b/frontend/src/main.js @@ -23,17 +23,22 @@ app.use(store) app.use(VueCookies) // let config=require("../config.json"); -fetch('/config.json').then(response => response.json()).then(config => { - console.log(config) - store.commit('setBaseURL', config.base_url) -}).then(() => { - const axiosInstance = axios.create({ - withCredentials: true, - baseURL: store.state.base_url, - }) - app.config.globalProperties.$axios = { ...axiosInstance } +// fetch('/config.json').then(response => response.json()).then(config => { +// console.log(config) +// store.commit('setBaseURL', config.base_url) +// }).then(() => { +// const axiosInstance = axios.create({ +// withCredentials: true, +// baseURL: store.state.base_url, +// }) +// app.config.globalProperties.$axios = { ...axiosInstance } +// }) + +const axiosInstance = axios.create({ + withCredentials: true, + baseURL: store.state.base_url, }) - +app.config.globalProperties.$axios = { ...axiosInstance } registerPlugins(app)