refactor: extract CurrentUser and CurrentUserID helpers
This commit is contained in:
26
internal/server/user.go
Normal file
26
internal/server/user.go
Normal 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
|
||||
}
|
||||
Reference in New Issue
Block a user