fix: check exists from c.Get

This commit is contained in:
2026-06-16 10:17:18 +02:00
committed by Milas Holsting
parent 8e43731d1f
commit 99fa808d30

View File

@@ -10,12 +10,16 @@ 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
}
user, exists := c.Get("User")
if !exists {
return nil
}
u, ok := user.(*domain.User)
if !ok {
return nil
}
return u
}
func CurrentUserID(c *gin.Context) string {
u := CurrentUser(c)