Skip to content
This repository was archived by the owner on Oct 8, 2022. It is now read-only.

Commit 917feda

Browse files
committed
feat: handle request to see self user
1 parent be95aed commit 917feda

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

routes.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ func (s *Server) registerRoutes() {
4242
v1.HandleFunc("/signin", s.handleSignin).Methods("POST")
4343
v1.HandleFunc("/token", s.mustAuth(s.handleCreateAccessToken)).Methods("GET")
4444

45+
// Users
46+
v1.HandleFunc("/user", s.mustAuth(s.selfUser)).Methods("GET")
47+
4548
// Reports
4649
v1.HandleFunc("/reports", s.mustAuth(s.createReport)).Methods("POST")
4750
v1.HandleFunc("/reports/"+idPathVar, s.mustAuth(s.retrieveReport)).Methods("GET")

user.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package server
2+
3+
import (
4+
"net/http"
5+
)
6+
7+
func (s *Server) selfUser(w http.ResponseWriter, r *http.Request) {
8+
user := userFromContext(r.Context())
9+
if user == nil {
10+
writeError(w, &ErrInternal)
11+
return
12+
}
13+
14+
writeJSON(w, user, 200)
15+
}

0 commit comments

Comments
 (0)