28 lines
485 B
Go
28 lines
485 B
Go
package handler
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
type UserHandler struct{}
|
|
|
|
func NewUserHandler() *UserHandler {
|
|
return &UserHandler{}
|
|
}
|
|
|
|
func (h *UserHandler) Me(c *gin.Context) {
|
|
claims, ok := CurrentClaims(c)
|
|
if !ok {
|
|
c.JSON(http.StatusUnauthorized, gin.H{"error": "missing current user"})
|
|
return
|
|
}
|
|
c.JSON(http.StatusOK, gin.H{
|
|
"id": claims.UserID,
|
|
"username": claims.Username,
|
|
"email": claims.Email,
|
|
"is_admin": claims.IsAdmin,
|
|
})
|
|
}
|