Reorganized API + added db migrations

Read the README file for more informations
This commit is contained in:
cdricms
2025-01-28 17:41:05 +01:00
parent 74118a5aa6
commit 501ffaea17
47 changed files with 608 additions and 219 deletions

33
backend/api/users/me.go Normal file
View File

@@ -0,0 +1,33 @@
package users
import (
"net/http"
"fr.latosa-escrima/api/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)
}