refactor: extract CurrentUser and CurrentUserID helpers

This commit is contained in:
2026-05-28 12:51:11 +02:00
committed by Milas Holsting
parent 8454d01b09
commit bf28c307c9
4 changed files with 67 additions and 102 deletions

26
internal/server/user.go Normal file
View File

@@ -0,0 +1,26 @@
package server
import (
"mal/internal/domain"
"github.com/gin-gonic/gin"
)
func CurrentUser(c *gin.Context) *domain.User {
if c == nil {
return nil
}
user, _ := c.Get("User")
if u, ok := user.(*domain.User); ok {
return u
}
return nil
}
func CurrentUserID(c *gin.Context) string {
u := CurrentUser(c)
if u == nil {
return ""
}
return u.ID
}