diff --git a/internal/handler/auth_handler.go b/internal/handler/auth_handler.go index bc25077..b9617ab 100644 --- a/internal/handler/auth_handler.go +++ b/internal/handler/auth_handler.go @@ -38,3 +38,19 @@ func (h *UserHandler) Login(c *fiber.Ctx) error { return utils.LogResponse(c, user, "Login successful") } + +func (h *UserHandler) Logout(c *fiber.Ctx) error { + + token := c.Get("Authorization") + if token == "" { + + return utils.ErrorResponse(c, "No token provided") + } + + err := utils.DeleteData(token) + if err != nil { + return utils.InternalServerErrorResponse(c, "Error logging out") + } + + return utils.NonPaginatedResponse(c, nil, 0, "Logout successful") +} diff --git a/presentation/auth_route.go b/presentation/auth_route.go index db16eda..a6d4dab 100644 --- a/presentation/auth_route.go +++ b/presentation/auth_route.go @@ -23,4 +23,5 @@ func AuthRouter(app *fiber.App) { userHandler := handler.NewUserHandler(userService) api.Post("/login", userHandler.Login) + api.Post("/logout", userHandler.Logout) }