fix(oidc): defer oidcCallback to prevent crash on startup

server.ts calls OidcService.initialize() inside the Express app setup, but
oidcRoutes.ts was calling OidcService.callback() at module-load time — before
initialize() had been called. This caused the server to crash immediately on
startup with "OidcService not initialized. Call initialize() first."

The fix wraps the callback in a lazy arrow function so it is only resolved
when the route handler fires, by which point initialize() has already run.
tsc --noEmit clean; server starts successfully after this change.
Co-authored-by: 's avatarCursor <cursoragent@cursor.com>
parent f39e8508
......@@ -3,7 +3,12 @@ import { OidcService } from './oidcService';
const router = express.Router();
const oidcCallback = OidcService.callback();
// oidcCallback must be invoked lazily — OidcService.getInstance() is only
// set after server.ts calls OidcService.initialize() during startup.
// Calling it at module-load time (as a plain `const`) crashes the server.
const oidcCallback = (req: express.Request, res: express.Response, next: express.NextFunction) => {
OidcService.callback()(req, res, next);
};
// /.well-known/openid-configuration
router.get('/.well-known/openid-configuration', oidcCallback);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment