Skip to content

Commit

Permalink
fix: change token name and same site lax rule
Browse files Browse the repository at this point in the history
  • Loading branch information
simon-ding committed Sep 2, 2024
1 parent b12bbd2 commit 32b595e
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions server/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func (s *Server) authModdleware(c *gin.Context) {
c.Next()
return
}
token, err := c.Cookie("token")
token, err := c.Cookie("polaris_token")
if err != nil {
log.Errorf("token error: %v", err)
c.AbortWithStatus(http.StatusForbidden)
Expand Down Expand Up @@ -90,20 +90,18 @@ func (s *Server) Login(c *gin.Context) (interface{}, error) {
if err != nil {
return nil, errors.Wrap(err, "sign")
}
c.SetSameSite(http.SameSiteNoneMode)
c.SetCookie("token", sig, 0, "/", "", false, false)
return gin.H{
"token": sig,
}, nil
c.SetSameSite(http.SameSiteLaxMode)
c.SetCookie("polaris_token", sig, 0, "/", "", false, false)
return "success", nil
}

func (s *Server) Logout(c *gin.Context) (interface{}, error) {
if !s.isAuthEnabled() {
return nil, errors.New( "auth is not enabled")
}

c.SetSameSite(http.SameSiteNoneMode)
c.SetCookie("token", "", -1, "/", "", true, false)
c.SetSameSite(http.SameSiteLaxMode)
c.SetCookie("polaris_token", "", -1, "/", "", true, false)
return nil, nil
}

Expand Down

0 comments on commit 32b595e

Please sign in to comment.