feat: add login middleware for protected routes
This commit is contained in:
@ -16,7 +16,16 @@ var (
|
||||
memcache cache.Cache
|
||||
)
|
||||
|
||||
// add middleware to login http requests; ai!
|
||||
// RequireLogin redirects unauthenticated users to the login page
|
||||
func RequireLogin(next http.Handler) http.Handler {
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
if r.Context().Value("username") == nil {
|
||||
http.Redirect(w, r, "/login", http.StatusFound)
|
||||
return
|
||||
}
|
||||
next.ServeHTTP(w, r)
|
||||
})
|
||||
}
|
||||
|
||||
func GetSession(next http.Handler) http.Handler {
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
|
Reference in New Issue
Block a user