Middleware for keeping track of users, login states and permissions