feat(auth): session carries org_id/role; add context helpers

This commit is contained in:
2026-07-21 16:28:06 +01:00
parent 022b1ef8ec
commit 066095ffca
2 changed files with 23 additions and 0 deletions
+21
View File
@@ -14,6 +14,27 @@ func GetSessionFromContext(c *gin.Context) *Session {
return sess
}
func OrgID(c *gin.Context) string {
if s := GetSessionFromContext(c); s != nil {
return s.OrgID
}
return ""
}
func Role(c *gin.Context) string {
if s := GetSessionFromContext(c); s != nil {
return s.Role
}
return ""
}
func UserID(c *gin.Context) string {
if s := GetSessionFromContext(c); s != nil {
return s.UserID
}
return ""
}
func Middleware() gin.HandlerFunc {
return func(c *gin.Context) {
if !authEnabled {
+2
View File
@@ -17,6 +17,8 @@ const statePrefix = "km:state:"
type Session struct {
UserID string `json:"user_id"`
OrgID string `json:"org_id"`
Role string `json:"role"`
Email string `json:"email"`
Name string `json:"name"`
}