Moved the cookie consts to a domain package

This commit is contained in:
James Tombleson 2024-04-14 18:33:17 -07:00
parent bd82bfeca0
commit 03d151f75a
2 changed files with 14 additions and 10 deletions

9
domain/consts.go Normal file
View File

@ -0,0 +1,9 @@
package domain
const (
CookieToken = "token"
CookieRefreshToken = "refresh"
CookieUser = "user"
CookieSettingsDarkMode = "darkmode"
)

View File

@ -3,6 +3,7 @@ package handlers
import (
"errors"
"templ-test/client"
"templ-test/domain"
"templ-test/models"
"templ-test/services"
"time"
@ -13,12 +14,6 @@ import (
"github.com/labstack/echo/v4"
)
const (
CookieToken = "token"
CookieRefreshToken = "refresh"
CookieUser = "user"
)
type Handlers struct {
api client.ApiClient
cfg services.EnvConfig
@ -91,17 +86,17 @@ func ValidateJwt(ctx echo.Context, sharedSecret, issuer string) (jwtToken, error
func GetCookieValues(ctx echo.Context) models.AllCookies {
m := models.AllCookies{}
token, err := ctx.Cookie(CookieToken)
token, err := ctx.Cookie(domain.CookieToken)
if err == nil {
m.Token = token.Value
}
user, err := ctx.Cookie(CookieUser)
user, err := ctx.Cookie(domain.CookieUser)
if err == nil {
m.Username = user.Value
}
refresh, err := ctx.Cookie(CookieRefreshToken)
refresh, err := ctx.Cookie(domain.CookieRefreshToken)
if err == nil {
m.RefreshToken = refresh.Value
}