This commit is contained in:
28
internal/api/middleware/logout.go
Normal file
28
internal/api/middleware/logout.go
Normal file
@@ -0,0 +1,28 @@
|
||||
package middleware
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"clintonambulance.com/calculate_negative_points/internal/config"
|
||||
)
|
||||
|
||||
func Logout(config *config.ApplicationConfig) func(http.Handler) http.Handler {
|
||||
return func(next http.Handler) http.Handler {
|
||||
fn := func(w http.ResponseWriter, r *http.Request) {
|
||||
session, _ := config.CookieStore.Get(r, config.SessionName)
|
||||
session.Options.MaxAge = -1
|
||||
|
||||
err := session.Save(r, w)
|
||||
|
||||
if err != nil {
|
||||
http.Error(w, "Failed to delete session", http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
w.WriteHeader(http.StatusOK)
|
||||
return
|
||||
}
|
||||
|
||||
return http.HandlerFunc(fn)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user