Middleware for user session management.