mirror of
https://github.com/AmanTahiliani/FHIR-Sandbox.git
synced 2026-08-07 19:56:17 -04:00
chore: remove DB and binary from repo, add .gitignore to exclude artifacts
This commit is contained in:
32
app/handlers/logout.go
Normal file
32
app/handlers/logout.go
Normal file
@@ -0,0 +1,32 @@
|
||||
// logout.go handles session invalidation and user logout.
|
||||
package handlers
|
||||
|
||||
import (
|
||||
"log"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
// HandleLogout invalidates the current session and redirects to the home page.
|
||||
// POST /logout
|
||||
func (h *Handler) HandleLogout(w http.ResponseWriter, r *http.Request) {
|
||||
cookie, err := r.Cookie(SessionCookieName)
|
||||
if err == nil && cookie.Value != "" {
|
||||
if delErr := h.store.DeleteSession(cookie.Value); delErr != nil {
|
||||
log.Printf("handlers: logout delete session %s: %v", cookie.Value, delErr)
|
||||
} else {
|
||||
log.Printf("handlers: logged out session %s", cookie.Value)
|
||||
}
|
||||
}
|
||||
|
||||
// Clear the cookie in the browser regardless of DB outcome.
|
||||
http.SetCookie(w, &http.Cookie{
|
||||
Name: SessionCookieName,
|
||||
Value: "",
|
||||
Path: "/",
|
||||
MaxAge: -1,
|
||||
HttpOnly: true,
|
||||
SameSite: http.SameSiteLaxMode,
|
||||
})
|
||||
|
||||
http.Redirect(w, r, "/", http.StatusSeeOther)
|
||||
}
|
||||
Reference in New Issue
Block a user