I am getting an erro while integration Auth0 with sample nodejs application

Hi, I am trying to integrate Auth0 with a sample Nodejs application but getting the following error. Anyone plz help.

Express is running on port 3000:
TypeError: Cannot read properties of undefined (reading ‘isAuthenticated’)
at D:\NodeJSDemo\routes\index.js:5:37
at Layer.handle [as handle_request] (D:\NodeJSDemo\node_modules\express\lib\router\layer.js:95:5)
at next (D:\NodeJSDemo\node_modules\express\lib\router\route.js:137:13)
at Route.dispatch (D:\NodeJSDemo\node_modules\express\lib\router\route.js:112:3)
at Layer.handle [as handle_request] (D:\NodeJSDemo\node_modules\express\lib\router\layer.js:95:5)
at D:\NodeJSDemo\node_modules\express\lib\router\index.js:281:22
at Function.process_params (D:\NodeJSDemo\node_modules\express\lib\router\index.js:335:12)
at next (D:\NodeJSDemo\node_modules\express\lib\router\index.js:275:10)
at Function.handle (D:\NodeJSDemo\node_modules\express\lib\router\index.js:174:3)
at router (D:\NodeJSDemo\node_modules\express\lib\router\index.js:47:12)

I had the same issue.

Just make sure that the Auth configuration is before the app.use, not after.

Example:
Before:

app.use('/', indexRouter);
app.use('/users', usersRouter);

// auth router attaches /login, /logout, and /callback routes to the baseURL
app.use(auth(config));

After(works):

// auth router attaches /login, /logout, and /callback routes to the baseURL
app.use(auth(config));
app.use('/', indexRouter);
app.use('/users', usersRouter);