begin
This commit is contained in:
33
server/handlers/logout.go
Normal file
33
server/handlers/logout.go
Normal 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)
|
||||
}
|
||||
Reference in New Issue
Block a user