add basic validation in auth request
This commit is contained in:
parent
deddd123a3
commit
23b58d63c4
@ -1,11 +1,31 @@
|
|||||||
package auth
|
package auth
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"github.com/go-playground/validator/v10"
|
||||||
|
|
||||||
"github.com/gofiber/fiber/v2"
|
"github.com/gofiber/fiber/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
func AuthHandler(c *fiber.Ctx) error {
|
func AuthHandler(c *fiber.Ctx) error {
|
||||||
return errors.New("not implemented")
|
validate := validator.New()
|
||||||
|
|
||||||
|
var req AuthRequest
|
||||||
|
|
||||||
|
if err := c.BodyParser(&req); err != nil {
|
||||||
|
return c.Status(fiber.StatusBadRequest).JSON(fiber.Map{
|
||||||
|
"error": "Invalid JSON format",
|
||||||
|
"details": err.Error(),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := validate.Struct(&req); err != nil {
|
||||||
|
return c.Status(fiber.StatusBadRequest).JSON(fiber.Map{
|
||||||
|
"error": "Validation failed",
|
||||||
|
"details": err.Error(),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
return c.Status(fiber.StatusOK).JSON(fiber.Map{
|
||||||
|
"message": "Authentication request processed successfully",
|
||||||
|
"data": req,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user