Files
pocket-id/backend/internal/utils/cookie/add_cookie.go
2026-07-10 16:31:45 -05:00

36 lines
1.0 KiB
Go

package cookie
import (
"net/http"
"time"
)
func NewAccessTokenCookie(maxAgeInSeconds int, token string) *http.Cookie {
return newCookie(AccessTokenCookieName, token, maxAgeInSeconds, "/")
}
func NewSessionIDCookie(maxAgeInSeconds int, sessionID string) *http.Cookie {
return newCookie(SessionIdCookieName, sessionID, maxAgeInSeconds, "/")
}
func NewDeviceTokenCookie(deviceToken string) *http.Cookie {
return newCookie(DeviceTokenCookieName, deviceToken, int(15*time.Minute.Seconds()), "/api/one-time-access-token")
}
func NewReauthenticationTokenCookie(reauthenticationToken string) *http.Cookie {
return newCookie(ReauthenticationTokenCookieName, reauthenticationToken, int(3*time.Minute.Seconds()), "/")
}
func newCookie(name, value string, maxAge int, path string) *http.Cookie {
// SameSite remains unset to preserve the cookies emitted by the existing Gin helpers
//nolint:gosec
return &http.Cookie{
Name: name,
Value: value,
Path: path,
MaxAge: maxAge,
Secure: true,
HttpOnly: true,
}
}