34 lines
648 B
Go
34 lines
648 B
Go
package users
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"fr.latosa-escrima/core"
|
|
"github.com/golang-jwt/jwt/v5"
|
|
)
|
|
|
|
func HandleMe(w http.ResponseWriter, r *http.Request) {
|
|
token, ok := r.Context().Value("token").(*jwt.Token)
|
|
if !ok {
|
|
core.JSONError{
|
|
Status: core.Error,
|
|
Message: "Couldn't retrieve your JWT.",
|
|
}.Respond(w, http.StatusInternalServerError)
|
|
return
|
|
}
|
|
|
|
claims, ok := token.Claims.(jwt.MapClaims)
|
|
if !ok {
|
|
core.JSONError{
|
|
Status: core.Error,
|
|
Message: "Invalid token claims.",
|
|
}.Respond(w, http.StatusInternalServerError)
|
|
return
|
|
}
|
|
|
|
uuid := claims["user_id"].(string)
|
|
|
|
r.SetPathValue("user_uuid", uuid)
|
|
HandleUser(w, r)
|
|
}
|