28 lines
644 B
Go
28 lines
644 B
Go
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: "/",
|
|
HttpOnly: true,
|
|
Domain: "." + os.Getenv("BASE_URL"), // must match what you set when logging in
|
|
Secure: true,
|
|
Expires: time.Unix(0, 0), // way in the past
|
|
MaxAge: -1, // tells browser to delete immediately
|
|
SameSite: http.SameSiteLaxMode,
|
|
}
|
|
|
|
http.SetCookie(w, cookie)
|
|
http.Redirect(w, r, config.BASE_URL, http.StatusSeeOther)
|
|
}
|