Middleware for session management
