31 lines
573 B
Go
31 lines
573 B
Go
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,
|
|
})
|
|
}
|