Add user information retrieval endpoint and update token management

This commit is contained in:
2025-05-18 10:29:08 +08:00
parent 1396f6939b
commit 1b5eb23a65
3 changed files with 48 additions and 1 deletions

View File

@@ -318,6 +318,23 @@ func handleSetUserBio(c fiber.Ctx) error {
})
}
// handleGetMe retrieves the current user's information and refreshes the token
func handleGetMe(c fiber.Ctx) error {
uid, ok := c.Locals("uid").(uint)
if !ok {
return model.NewUnAuthorizedError("Unauthorized")
}
user, err := service.GetMe(uid)
if err != nil {
return err
}
return c.Status(fiber.StatusOK).JSON(model.Response[model.UserViewWithToken]{
Success: true,
Data: user,
Message: "User information retrieved successfully",
})
}
func AddUserRoutes(r fiber.Router) {
u := r.Group("user")
u.Post("/register", handleUserRegister)
@@ -333,4 +350,5 @@ func AddUserRoutes(r fiber.Router) {
u.Get("/info", handleGetUserInfo)
u.Post("/username", handleChangeUsername)
u.Post("/bio", handleSetUserBio)
u.Get("/me", handleGetMe)
}