Skip to content

Commit

Permalink
fix: set-cookie 跨域问题
Browse files Browse the repository at this point in the history
  • Loading branch information
RockChinQ committed Apr 12, 2024
1 parent ab0010f commit 647f3e1
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion backend/controller/accapi.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package controller

import (
"net/http"

"github.com/RockChinQ/Campux/backend/service"
"github.com/gin-gonic/gin"
)
Expand Down Expand Up @@ -68,8 +70,19 @@ func (ar *AccountRouter) LoginAccount(c *gin.Context) {
return
}

domain := c.Request.Header.Get("Origin")

// set-cookie
c.SetCookie("access-token", token, 3600, "/", c.Request.Host, false, true)
http.SetCookie(c.Writer, &http.Cookie{
Name: "access-token",
Value: token,
Path: "/",
Domain: domain,
Secure: false,
SameSite: http.SameSiteNoneMode,
HttpOnly: true,
MaxAge: 3600,
})

ar.Success(c, gin.H{
"token": token,
Expand Down

0 comments on commit 647f3e1

Please sign in to comment.