diff options
| -rw-r--r-- | src/sessions/middleware.go | 18 |
1 files changed, 9 insertions, 9 deletions
diff --git a/src/sessions/middleware.go b/src/sessions/middleware.go index c1d0528..6bb3b15 100644 --- a/src/sessions/middleware.go +++ b/src/sessions/middleware.go @@ -27,23 +27,23 @@ func SetSession(next http.Handler) http.Handler { func GuestSession(next http.Handler) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - // if SessionKey does not exist then this is a valid guest request - if _, ok := r.Context().Value(SessionCtxKey("session")); !ok { - next.ServeHTTP(w, r) + // if SessionKey does exist then redirect to `/u/me` as this is an auth session + if v := r.Context().Value(SessionCtxKey("session")); v != nil { + http.Redirect(w, r, "/u/me", http.StatusSeeOther) } - // else redirect to `/u/me` as this is an auth session - http.Redirect(w, r, "/u/me", http.StatusSeeOther) + // else this is a valid guest request + next.ServeHTTP(w, r) }) } func AuthSession(next http.Handler) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - // if session key not exists, then this is a guest session request redirect to login page - if _, ok := r.Context().Value(SessionCtxKey("session")); !ok { + // if session key exists then this is a valid auth request + if v := r.Context().Value(SessionCtxKey("session")); v != nil { http.Redirect(w, r, "/login", http.StatusSeeOther) } - // else this is a valid auth session request - next.ServeHTTP(w, r) + // else this is a guest session request, redirect to login + http.Redirect(w, r, "/login", http.StatusSeeOther) }) } |
