Fixed middleware
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user