Fixed middleware

This commit is contained in:
Pablu23
2024-05-22 22:16:50 +02:00
parent 392114b240
commit f905d482a5
4 changed files with 32 additions and 20 deletions

View File

@@ -6,16 +6,12 @@ import (
func (s *Server) Auth(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
cookie, err := r.Cookie("auth")
if err != nil {
if r.URL.Path == "/login" || r.URL.Path == "/login/" {
next.ServeHTTP(w, r)
return
}
http.Redirect(w, r, "/login", http.StatusFound)
cookie, _ := r.Cookie("auth")
if r.URL.Path == "/login" || r.URL.Path == "/login/" {
next.ServeHTTP(w, r)
return
}
if cookie.Value == s.secret {
if cookie != nil && cookie.Value == s.secret {
next.ServeHTTP(w, r)
} else {
http.Redirect(w, r, "/login", http.StatusFound)