This commit is contained in:
metacryst
2025-09-06 20:26:07 -05:00
parent 7194b48b14
commit eff0c160a5
47 changed files with 2470 additions and 254 deletions

33
server/handlers/logout.go Normal file
View File

@@ -0,0 +1,33 @@
package handlers
import (
"net/http"
"time"
"os"
"hyperia/config"
)
func HandleLogout(w http.ResponseWriter, r *http.Request) {
// Create a cookie with the same name and domain, but expired
cookie := &http.Cookie{
Name: "auth_token",
Value: "",
Path: "/",
Domain: "." + os.Getenv("BASE_URL"), // must match what you set when logging in
HttpOnly: true,
Secure: true,
Expires: time.Unix(0, 0), // way in the past
MaxAge: -1, // tells browser to delete immediately
SameSite: http.SameSiteLaxMode,
}
if config.ENV == "development" {
cookie.Secure = false
cookie.Domain = ".hyperia.local"
}
http.SetCookie(w, cookie)
http.Redirect(w, r, config.BASE_URL, http.StatusSeeOther)
}