Skip to content
Snippets Groups Projects
Commit f37bcd24 authored by Dean's avatar Dean
Browse files

add /users/me route

parent a0a1cc25
No related branches found
Tags v1.4.0
No related merge requests found
package routes
import (
"net/http"
"owo.codes/whats-this/api/lib/apierrors"
"owo.codes/whats-this/api/lib/middleware"
"github.com/go-chi/render"
)
// Me handles /users/me requests.
func Me(w http.ResponseWriter, r *http.Request) {
// Only authorized users can use this route
user := middleware.GetAuthorizedUser(r)
if user.ID == "" || user.IsBlocked {
panic(apierrors.Unauthorized)
}
// Return response
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusOK)
render.JSON(w, r, user)
}
......@@ -145,6 +145,7 @@ func main() {
r.Post("/upload/pomf", routes.UploadPomf(false))
r.Post("/upload/pomf/associated", routes.UploadPomf(true))
r.Post("/users", routes.CreateUser)
r.Get("/users/me", routes.Me)
// MethodNotAllowed handler
r.MethodNotAllowed(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment