You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
24 lines
584 B
24 lines
584 B
package middleware
|
|
|
|
import (
|
|
"marmic/servicetrade-toolbox/internal/api"
|
|
"net/http"
|
|
)
|
|
|
|
func AuthMiddleware(next http.Handler) http.Handler {
|
|
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
cookie, err := r.Cookie("PHPSESSID")
|
|
if err != nil {
|
|
http.Redirect(w, r, "/login", http.StatusSeeOther)
|
|
return
|
|
}
|
|
|
|
session := api.NewSession()
|
|
session.Cookie = "PHPSESSID=" + cookie.Value
|
|
|
|
// You might want to add a method to validate the session token
|
|
// For now, we'll assume if the cookie exists, the session is valid
|
|
|
|
next.ServeHTTP(w, r)
|
|
})
|
|
}
|
|
|