add frontend template + GET /users/{userRef} route
This commit is contained in:
parent
5a75f99720
commit
580449440a
28 changed files with 1393 additions and 12 deletions
|
@ -4,6 +4,7 @@ import (
|
|||
"context"
|
||||
"net/http"
|
||||
|
||||
"github.com/go-chi/render"
|
||||
"gitlab.com/1f320/pronouns/backend/server/auth"
|
||||
)
|
||||
|
||||
|
@ -34,7 +35,12 @@ func MustAuth(next http.Handler) http.Handler {
|
|||
fn := func(w http.ResponseWriter, r *http.Request) {
|
||||
_, ok := ClaimsFromContext(r.Context())
|
||||
if !ok {
|
||||
|
||||
render.Status(r, errCodeStatuses[ErrForbidden])
|
||||
render.JSON(w, r, APIError{
|
||||
Code: ErrForbidden,
|
||||
Message: errCodeMessages[ErrForbidden],
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
next.ServeHTTP(w, r)
|
||||
|
|
|
@ -62,13 +62,36 @@ func (e *APIError) prepare() {
|
|||
|
||||
// Error code constants
|
||||
const (
|
||||
ErrBadRequest = 400
|
||||
ErrForbidden = 403
|
||||
ErrInternalServerError = 500 // catch-all code for unknown errors
|
||||
|
||||
// Login/authorize error codes
|
||||
ErrInvalidState = 1001
|
||||
ErrInvalidOAuthCode = 1002
|
||||
|
||||
// User-related error codes
|
||||
ErrUserNotFound = 2001
|
||||
)
|
||||
|
||||
var errCodeMessages = map[int]string{
|
||||
ErrBadRequest: "Bad request",
|
||||
ErrForbidden: "Forbidden",
|
||||
ErrInternalServerError: "Internal server error",
|
||||
|
||||
ErrInvalidState: "Invalid OAuth state",
|
||||
ErrInvalidOAuthCode: "Invalid OAuth code",
|
||||
|
||||
ErrUserNotFound: "User not found",
|
||||
}
|
||||
|
||||
var errCodeStatuses = map[int]int{
|
||||
ErrBadRequest: http.StatusBadRequest,
|
||||
ErrForbidden: http.StatusForbidden,
|
||||
ErrInternalServerError: http.StatusInternalServerError,
|
||||
|
||||
ErrInvalidState: http.StatusBadRequest,
|
||||
ErrInvalidOAuthCode: http.StatusForbidden,
|
||||
|
||||
ErrUserNotFound: http.StatusNotFound,
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue