added auth validate route

This commit is contained in:
2025-01-28 18:09:26 +01:00
parent f7efee56f0
commit 86c43fffc0
4 changed files with 31 additions and 5 deletions

View File

@@ -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)})
}