Reorganized API + added db migrations
Read the README file for more informations
This commit is contained in:
33
backend/api/users/me.go
Normal file
33
backend/api/users/me.go
Normal 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)
|
||||
}
|
||||
Reference in New Issue
Block a user