Verbose debug printing in login endpoint
This commit is contained in:
parent
3e00a532cf
commit
9240d5e052
1 changed files with 5 additions and 0 deletions
|
@ -57,9 +57,11 @@ func (gs *GState) Login(c *fiber.Ctx) error {
|
||||||
// The body type is identical to a NewUser
|
// The body type is identical to a NewUser
|
||||||
u := new(types.NewUser)
|
u := new(types.NewUser)
|
||||||
if err := c.BodyParser(u); err != nil {
|
if err := c.BodyParser(u); err != nil {
|
||||||
|
println("Error parsing body")
|
||||||
return c.Status(400).SendString(err.Error())
|
return c.Status(400).SendString(err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
println("Username:", u.Username)
|
||||||
if !gs.Db.CheckUser(u.Username, u.Password) {
|
if !gs.Db.CheckUser(u.Username, u.Password) {
|
||||||
println("User not found")
|
println("User not found")
|
||||||
return c.SendStatus(fiber.StatusUnauthorized)
|
return c.SendStatus(fiber.StatusUnauthorized)
|
||||||
|
@ -74,13 +76,16 @@ func (gs *GState) Login(c *fiber.Ctx) error {
|
||||||
|
|
||||||
// Create token
|
// Create token
|
||||||
token := jwt.NewWithClaims(jwt.SigningMethodHS256, claims)
|
token := jwt.NewWithClaims(jwt.SigningMethodHS256, claims)
|
||||||
|
println("Token created for user:", u.Username)
|
||||||
|
|
||||||
// Generate encoded token and send it as response.
|
// Generate encoded token and send it as response.
|
||||||
t, err := token.SignedString([]byte("secret"))
|
t, err := token.SignedString([]byte("secret"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
println("Error signing token")
|
||||||
return c.SendStatus(fiber.StatusInternalServerError)
|
return c.SendStatus(fiber.StatusInternalServerError)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
println("Successfully signed token for user:", u.Username)
|
||||||
return c.JSON(fiber.Map{"token": t})
|
return c.JSON(fiber.Map{"token": t})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue