Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion middleware/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const enforceLeadingSlash = (path) => {
const auth = function (params) {
const config = getConfig(params);
debug('configuration object processed, resulting configuration: %O', config);
const router = new express.Router();
const router = new express();
Copy link

Copilot AI Jul 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using express() instead of express.Router() creates a full Express application instance rather than just a router. This is a significant architectural change that may have unintended consequences. An Express app has additional overhead and functionality (like settings, engines, etc.) that may not be needed. Consider if this change could cause conflicts when the returned object is used as middleware in another Express app.

Suggested change
const router = new express();
const router = express.Router();

Copilot uses AI. Check for mistakes.
const transient = new TransientCookieHandler(config);

router.use(appSession(config));
Expand Down
20 changes: 12 additions & 8 deletions test/login.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,10 @@ describe('auth', () => {
it('should contain the default authentication routes', async () => {
const router = auth(defaultConfig);
server = await createServer(router);
assert.ok(router.stack.some(filterRoute('GET', '/login')));
assert.ok(router.stack.some(filterRoute('GET', '/logout')));
assert.ok(router.stack.some(filterRoute('POST', '/callback')));
assert.ok(router.stack.some(filterRoute('GET', '/callback')));
assert.ok(router._router.stack.some(filterRoute('GET', '/login')));
assert.ok(router._router.stack.some(filterRoute('GET', '/logout')));
assert.ok(router._router.stack.some(filterRoute('POST', '/callback')));
assert.ok(router._router.stack.some(filterRoute('GET', '/callback')));
Comment on lines +66 to +69
Copy link

Copilot AI Jul 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Accessing the private _router property indicates a potential code smell. This implementation detail of Express may change in future versions, making the code brittle. The need to access _router.stack suggests that using express() instead of express.Router() may not be the optimal solution for the stated goal.

Suggested change
assert.ok(router._router.stack.some(filterRoute('GET', '/login')));
assert.ok(router._router.stack.some(filterRoute('GET', '/logout')));
assert.ok(router._router.stack.some(filterRoute('POST', '/callback')));
assert.ok(router._router.stack.some(filterRoute('GET', '/callback')));
const routes = getRoutes(router);
assert.ok(routes.some((r) => r.path === '/login' && r.methods.get));
assert.ok(routes.some((r) => r.path === '/logout' && r.methods.get));
assert.ok(routes.some((r) => r.path === '/callback' && r.methods.post));
assert.ok(routes.some((r) => r.path === '/callback' && r.methods.get));

Copilot uses AI. Check for mistakes.
});

it('should contain custom authentication routes', async () => {
Expand All @@ -79,10 +79,14 @@ describe('auth', () => {
},
});
server = await createServer(router);
assert.ok(router.stack.some(filterRoute('GET', '/custom-login')));
assert.ok(router.stack.some(filterRoute('GET', '/custom-logout')));
assert.ok(router.stack.some(filterRoute('POST', '/custom-callback')));
assert.ok(router.stack.some(filterRoute('GET', '/custom-callback')));
assert.ok(router._router.stack.some(filterRoute('GET', '/custom-login')));
assert.ok(router._router.stack.some(filterRoute('GET', '/custom-logout')));
assert.ok(
router._router.stack.some(filterRoute('POST', '/custom-callback'))
);
assert.ok(
router._router.stack.some(filterRoute('GET', '/custom-callback'))
);
});

it('should redirect to the authorize url for /login', async () => {
Expand Down