This commit is contained in:
2026-02-15 17:16:22 +03:00
commit 14815e521b
7 changed files with 257 additions and 0 deletions

30
auth/cookies.go Normal file
View File

@@ -0,0 +1,30 @@
package auth
import (
"net/http"
"time"
)
func SetUserCookie(w http.ResponseWriter, token string, expiryTime time.Time) {
http.SetCookie(w, &http.Cookie{
Name: "token",
Value: token,
Secure: true,
HttpOnly: true,
Path: "/",
Expires: expiryTime,
SameSite: http.SameSiteStrictMode,
})
}
func RemoveUserCookie(w http.ResponseWriter) {
http.SetCookie(w, &http.Cookie{
Name: "token",
Value: "",
Secure: true,
HttpOnly: true,
Path: "/",
Expires: time.Now().Add(-time.Hour),
SameSite: http.SameSiteStrictMode,
})
}