Trying to debug cookies

This commit is contained in:
James Tombleson 2024-05-12 10:45:16 -07:00
parent a10358ff91
commit b55ad0a99b
5 changed files with 62 additions and 0 deletions

View File

@ -0,0 +1,23 @@
package handlers
import (
"net/http"
"git.jamestombleson.com/jtom38/newsbot-portal/internal/domain"
"git.jamestombleson.com/jtom38/newsbot-portal/internal/models"
"git.jamestombleson.com/jtom38/newsbot-portal/internal/views/debug"
"github.com/labstack/echo/v4"
)
func (h *Handler) DebugCookies(c echo.Context) error {
user, _ := c.Cookie(domain.CookieUser)
token, _ := c.Cookie(domain.CookieToken)
refresh, _ := c.Cookie(domain.CookieRefreshToken)
model := models.DebugCookiesViewModel{
Username: user.Value,
Token: token.Value,
RefreshToken: refresh.Value,
}
return Render(c, http.StatusOK, debug.Cookies(model))
}

View File

@ -60,6 +60,12 @@ func NewServer(ctx context.Context, configs config.Configs, apiClient apiclient.
router.GET("/", s.HomeIndex) router.GET("/", s.HomeIndex)
router.GET("/about", s.HomeAbout) router.GET("/about", s.HomeAbout)
debug := router.Group("/debug")
debug.GET("/cookies", s.DebugCookies)
articles := router.Group("/articles")
articles.GET("", s.ArticlesList)
users := router.Group("/users") users := router.Group("/users")
users.GET("/login", s.UserLogin) users.GET("/login", s.UserLogin)
users.POST("/login", s.UserAfterLogin) users.POST("/login", s.UserAfterLogin)

14
internal/handlers/util.go Normal file
View File

@ -0,0 +1,14 @@
package handlers
import (
"net/http"
"github.com/labstack/echo/v4"
)
func SetCookie(c echo.Context, key string, value string) {
cookie := new(http.Cookie)
cookie.Name = key
cookie.Value = value
c.SetCookie(cookie)
}

7
internal/models/debug.go Normal file
View File

@ -0,0 +1,7 @@
package models
type DebugCookiesViewModel struct {
Username string
Token string
RefreshToken string
}

View File

@ -0,0 +1,12 @@
package debug
import "git.jamestombleson.com/jtom38/newsbot-portal/internal/views/layout"
import "git.jamestombleson.com/jtom38/newsbot-portal/internal/models"
templ Cookies(vm models.DebugCookiesViewModel) {
@layout.WithTemplate() {
Token: { vm.Token }
RefreshToken: { vm.RefreshToken }
UserName: { vm.Username }
}
}