added auth validate route
This commit is contained in:
@@ -131,6 +131,13 @@ func Login(c *fiber.Ctx) error {
|
||||
return c.Status(fiber.StatusOK).JSON(fiber.Map{"message": "Successfully logged in", "username": u.Username, "user_id": userId})
|
||||
}
|
||||
|
||||
//func ValidateToken(c *fiber.Ctx) error {
|
||||
//
|
||||
//}
|
||||
func ValidateToken(c *fiber.Ctx) error {
|
||||
username := c.Locals("username")
|
||||
userId := c.Locals("user_id")
|
||||
|
||||
if userId == nil || username == nil {
|
||||
fmt.Println("userId or username is nil")
|
||||
return c.Status(fiber.StatusBadRequest).JSON(fiber.Map{"error": "invalid token"})
|
||||
}
|
||||
return c.Status(fiber.StatusOK).JSON(fiber.Map{"message": "authorized", "username": c.Locals("username").(string), "user_id": c.Locals("userId").(string)})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user