Compare commits
No commits in common. "b47d5b2bbece10db45763b3885f2a15f4cbe553f" and "7a1644b9e33646f276d9009229d916b091a9837c" have entirely different histories.
b47d5b2bbe
...
7a1644b9e3
|
@ -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 {
|
func (m *Middleware) ProtectedRoute(next http.Handler) http.Handler {
|
||||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
session, err := m.s.Get(r)
|
session, err := m.s.Get(r)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
w.WriteHeader(http.StatusUnauthorized)
|
http.Redirect(w, r, "/signin", http.StatusSeeOther)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
token := session.Values["access_token"]
|
token := session.Values["access_token"]
|
||||||
|
|
||||||
if token == "" || token == nil {
|
if token == "" || token == nil {
|
||||||
w.WriteHeader(http.StatusUnauthorized)
|
http.Redirect(w, r, "/signin", http.StatusSeeOther)
|
||||||
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)
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue