Private
Public Access
34 lines
602 B
Go
34 lines
602 B
Go
package auth
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"repuestera_back/dto"
|
|
"repuestera_back/utils"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
func Me(c *gin.Context) {
|
|
userID, ok := c.Get("userID")
|
|
if !ok {
|
|
c.JSON(http.StatusUnauthorized, gin.H{"error": "usuario no autenticado"})
|
|
return
|
|
}
|
|
|
|
id, ok := userID.(uint)
|
|
if !ok {
|
|
c.JSON(http.StatusUnauthorized, gin.H{"error": "invalid token claims"})
|
|
return
|
|
}
|
|
|
|
permisos, _ := utils.PermisosDelContexto(c)
|
|
|
|
c.JSON(http.StatusOK, dto.MeResponse{
|
|
ID: id,
|
|
Email: c.GetString("email"),
|
|
Name: c.GetString("name"),
|
|
Permissions: permisos,
|
|
})
|
|
}
|