auth_logout.go 565 B

1234567891011121314151617181920212223242526272829303132
  1. package admin
  2. import (
  3. "time"
  4. "github.com/gofiber/fiber/v2"
  5. )
  6. type logoutPage struct {
  7. configService ConfigService
  8. }
  9. func NewLogoutPageHandler(
  10. configService ConfigService,
  11. ) fiber.Handler {
  12. handler := logoutPage{
  13. configService: configService,
  14. }
  15. return handler.handler()
  16. }
  17. func (h logoutPage) handler() fiber.Handler {
  18. return func(fctx *fiber.Ctx) error {
  19. cookie := new(fiber.Cookie)
  20. cookie.Name = h.configService.JWTCookie()
  21. cookie.Expires = time.Now().Add(-1 * time.Second)
  22. fctx.Cookie(cookie)
  23. return fctx.Redirect("/admin/login")
  24. }
  25. }