Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
fix(oauth): read the auth factory through its CommonJS interop
Elian Doran5954e7b87991
diff --git a/.claude/skills/analyzing-backend-bundle/check-dynamic-imports.mjs b/.claude/skills/analyzing-backend-bundle/check-dynamic-imports.mjsindex 2c2b376eb1..6a1112e281 100644--- a/.claude/skills/analyzing-backend-bundle/check-dynamic-imports.mjs+++ b/.claude/skills/analyzing-backend-bundle/check-dynamic-imports.mjs@@ -56,8 +56,20 @@ for (const file of files) {console.log(`BROKEN ${path.basename(file)} -> ${path.basename(m[2])} wants=[${wanted}] exports=[${[...has].slice(0, 5)}]`);}}+ // The other spelling of the same read: `(await import("./x.mjs")).name`+ // reaches straight into the namespace and breaks identically.+ for (const m of src.matchAll(/\(await import\("\.\/([^"]+\.mjs)"\)\)\.([A-Za-z_$][\w$]*)/g)) {+ const target = path.join(chunkDir, path.basename(m[1]));+ if (!exportCache.has(target)) exportCache.set(target, exportedNames(target));+ const has = exportCache.get(target);+ checked++;+ if (!has.has(m[2])) {+ broken++;+ console.log(`BROKEN ${path.basename(file)} -> ${path.basename(m[1])} wants=[${m[2]}] exports=[${[...has].slice(0, 5)}]`);+ }+ }}-console.log(`\n${checked} destructuring dynamic imports checked, ${broken} broken`);+console.log(`\n${checked} dynamic import reads checked, ${broken} broken`);if (broken) {console.log("Fix: read the module object through its CJS interop, e.g.\n" +" const mod = await import(\"pkg\");\n" +diff --git a/apps/server/src/services/open_id.ts b/apps/server/src/services/open_id.tsindex 90198af51e..ade14bc021 100644--- a/apps/server/src/services/open_id.ts+++ b/apps/server/src/services/open_id.ts@@ -328,7 +328,11 @@ export function createReactiveOidcMiddleware(deps: Partial<ReactiveOidcDeps> = {// only evaluated the first time OAuth is actually used, never on a server that runs with// OAuth unselected. The sole static reference to the package is the erased `Session` type// import, so the bundler keeps it out of the eager-init graph (see scripts/build-utils.ts).- const authFactory = buildAuth ?? (await import("express-openid-connect")).auth;+ // `express-openid-connect` is CommonJS, and the ESM split build emits it as a chunk+ // whose only export is `default`, so reading `.auth` off the namespace yields+ // undefined. Go through the interop.+ const oidc = await import("express-openid-connect");+ const authFactory = buildAuth ?? (oidc.default ?? oidc).auth;const { endSessionSupported, issuerBaseUrl, idTokenSigningAlg, metadataAvailable } = await probe();const built = authFactory(buildOAuthConfig(endSessionSupported, issuerBaseUrl, idTokenSigningAlg));