pollo/api/signout.go

28 lines
629 B
Go
Raw Normal View History

2024-06-27 21:51:00 -06:00
package api
import (
2024-09-16 13:46:25 -06:00
"log"
2024-06-27 21:51:00 -06:00
"net/http"
"pollo/lib"
"github.com/labstack/echo/v4"
)
func SignOutUserHandler(c echo.Context) error {
2024-09-16 13:46:25 -06:00
sessionData, err := lib.GetSessionCookie(c.Request(), "session")
if err == nil && sessionData != nil {
// Delete the session from the database
2024-11-21 00:48:45 -06:00
err = lib.DeleteSession(lib.GetDB(), sessionData.SessionID)
2024-09-16 13:46:25 -06:00
if err != nil {
log.Printf("Error deleting session: %v", err)
}
}
2024-06-27 21:51:00 -06:00
// Clear the session cookie
2024-06-28 00:35:58 -06:00
lib.ClearSessionCookie(c.Response().Writer, "session")
2024-06-27 21:51:00 -06:00
2024-09-16 13:46:25 -06:00
// Proceed with logout success logic
2024-06-27 21:51:00 -06:00
c.Response().Header().Set("HX-Redirect", "/")
return c.NoContent(http.StatusOK)
}