Files
uPortal2/backend/internal/auth/handler.go
T
2026-10-21 19:41:26 +03:00

32 lines
671 B
Go

package auth
import (
"net/http"
"time"
)
func SigninSetup(w http.ResponseWriter, cookieName, cookieValue string, expiresAt time.Time, secure bool) {
maxAge := expiresAt.Sub(time.Now().UTC())
http.SetCookie(w, &http.Cookie{
Name: cookieName,
Value: cookieValue,
Path: "/",
HttpOnly: true,
SameSite: http.SameSiteLaxMode,
Secure: secure,
MaxAge: int(maxAge.Seconds()),
})
}
func SignoutCleanup(w http.ResponseWriter, cookieName string, secure bool) {
http.SetCookie(w, &http.Cookie{
Name: cookieName,
Value: "",
Path: "/",
HttpOnly: true,
Secure: secure,
SameSite: http.SameSiteLaxMode,
MaxAge: -1,
})
}