Compare commits

..

No commits in common. "b47d5b2bbece10db45763b3885f2a15f4cbe553f" and "7a1644b9e33646f276d9009229d916b091a9837c" have entirely different histories.

1 changed files with 2 additions and 23 deletions

View File

@ -47,39 +47,18 @@ func (m *Middleware) AddUserInfo(next http.Handler) http.Handler {
})
}
// ProtectedRoute Checks if session and token are present, if not return a 401 response
func (m *Middleware) ProtectedRoute(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
session, err := m.s.Get(r)
if err != nil {
w.WriteHeader(http.StatusUnauthorized)
http.Redirect(w, r, "/signin", http.StatusSeeOther)
return
}
token := session.Values["access_token"]
if token == "" || token == nil {
w.WriteHeader(http.StatusUnauthorized)
return
}
next.ServeHTTP(w, r)
})
}
// ProtectedRouteWithRedirect Checks if session and token are present, if not return a redirect to /login
func (m *Middleware) ProtectedRouteWithRedirect(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
session, err := m.s.Get(r)
if err != nil {
http.Redirect(w, r, "/login", http.StatusSeeOther)
return
}
token := session.Values["access_token"]
if token == "" || token == nil {
http.Redirect(w, r, "/login", http.StatusSeeOther)
http.Redirect(w, r, "/signin", http.StatusSeeOther)
return
}