improve auth interface, fix issue in meta

This commit is contained in:
2025-04-02 21:18:29 +00:00
parent bd0387976f
commit 13339cc56d
7 changed files with 26 additions and 20 deletions

View File

@@ -151,7 +151,7 @@ var Icons = map[string]map[string]Icon{
Clickable: false,
},
},
"uknown": {
"unknown": {
"status": {
Src: "images/status/inactive.svg",
Alt: "Node is offline",

View File

@@ -33,3 +33,9 @@ type RequestContext struct {
Cookies map[string]string
Body map[string]any
}
type Auth struct {
Username string
Token string
CSRF string
}

View File

@@ -179,14 +179,14 @@ func RequestGetAPI(path string, context RequestContext) (*http.Response, int, er
return response, response.StatusCode, nil
}
func GetAuth(c *gin.Context) (string, string, string, error) {
func GetAuth(c *gin.Context) (Auth, error) {
_, errAuth := c.Cookie("auth")
username, errUsername := c.Cookie("username")
token, errToken := c.Cookie("PVEAuthCookie")
csrf, errCSRF := c.Cookie("CSRFPreventionToken")
if errUsername != nil || errAuth != nil || errToken != nil || errCSRF != nil {
return "", "", "", fmt.Errorf("error occured getting user cookies: (auth: %s, token: %s, csrf: %s)", errAuth, errToken, errCSRF)
return Auth{}, fmt.Errorf("error occured getting user cookies: (auth: %s, token: %s, csrf: %s)", errAuth, errToken, errCSRF)
} else {
return username, token, csrf, nil
return Auth{username, token, csrf}, nil
}
}