mirror of
https://github.com/YspCoder/clawgo.git
synced 2026-05-19 12:23:25 +08:00
fix webui white screen: persist token via cookie for asset/api auth
This commit is contained in:
@@ -133,6 +133,16 @@ func (s *RegistryServer) handleWebUI(w http.ResponseWriter, r *http.Request) {
|
|||||||
http.Error(w, "unauthorized", http.StatusUnauthorized)
|
http.Error(w, "unauthorized", http.StatusUnauthorized)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
if s.token != "" {
|
||||||
|
http.SetCookie(w, &http.Cookie{
|
||||||
|
Name: "clawgo_webui_token",
|
||||||
|
Value: s.token,
|
||||||
|
Path: "/",
|
||||||
|
HttpOnly: true,
|
||||||
|
SameSite: http.SameSiteLaxMode,
|
||||||
|
MaxAge: 86400,
|
||||||
|
})
|
||||||
|
}
|
||||||
if s.tryServeWebUIDist(w, r, "/webui/index.html") {
|
if s.tryServeWebUIDist(w, r, "/webui/index.html") {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -372,6 +382,9 @@ func (s *RegistryServer) checkAuth(r *http.Request) bool {
|
|||||||
if strings.TrimSpace(r.URL.Query().Get("token")) == s.token {
|
if strings.TrimSpace(r.URL.Query().Get("token")) == s.token {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
if c, err := r.Cookie("clawgo_webui_token"); err == nil && strings.TrimSpace(c.Value) == s.token {
|
||||||
|
return true
|
||||||
|
}
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user