fix: check exists from c.Get
This commit is contained in:
@@ -10,11 +10,15 @@ func CurrentUser(c *gin.Context) *domain.User {
|
|||||||
if c == nil {
|
if c == nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
user, _ := c.Get("User")
|
user, exists := c.Get("User")
|
||||||
if u, ok := user.(*domain.User); ok {
|
if !exists {
|
||||||
return u
|
return nil
|
||||||
}
|
}
|
||||||
return nil
|
u, ok := user.(*domain.User)
|
||||||
|
if !ok {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return u
|
||||||
}
|
}
|
||||||
|
|
||||||
func CurrentUserID(c *gin.Context) string {
|
func CurrentUserID(c *gin.Context) string {
|
||||||
|
|||||||
Reference in New Issue
Block a user