Skip to content

Commit

Permalink
use the request validator to validate auth request body in register r…
Browse files Browse the repository at this point in the history
…oute
  • Loading branch information
juancwu committed Dec 21, 2024
1 parent b1e5fba commit 4a86714
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions backend/internal/v1/v1_auth/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,12 @@ Route handles incoming requests to register/create a new account.
- HTTP-only cookie is also set with the refresh token value
*/
func (h *Handler) handleRegister(c echo.Context) error {
reqBodyBytes, err := io.ReadAll(c.Request().Body)
if err != nil {
return v1_common.Fail(c, http.StatusInternalServerError, "", err)
}
var reqBody AuthRequest
err = json.Unmarshal(reqBodyBytes, &reqBody)
if err != nil {
return v1_common.Fail(c, http.StatusInternalServerError, "", err)
if err := c.Bind(&reqBody); err != nil {
return v1_common.Fail(c, http.StatusBadRequest, "Invalid request body", err)
}
if err := c.Validate(&reqBody); err != nil {
return v1_common.Fail(c, http.StatusBadRequest, "Invalid request body", err)
}

ctx, cancel := context.WithTimeout(c.Request().Context(), time.Minute)
Expand Down

0 comments on commit 4a86714

Please sign in to comment.