diff --git a/memory-bank/change-log.md b/memory-bank/change-log.md index f0fad0e1..d1274006 100644 --- a/memory-bank/change-log.md +++ b/memory-bank/change-log.md @@ -689,3 +689,39 @@ Validation: Follow-ups: - Optional further hygiene pass can target remaining oversized commented historical sections in non-sensitive handlers. + +--- + +### CL-018: TASK22224 nextauth notify micro-refactor + +date: 2026-03-24 +author: Cline +scope: `pages/api/auth/[...nextauth].js` +type: change +rationale: Execute the explicitly approved auth micro-slice by replacing inline promise `.catch(...)` with explicit `try/catch` while preserving existing auth behavior. +impact: Auth-sensitive non-functional refactor only; keeps current sign-in flow, template/locale routing, and error-handling semantics unchanged. +status: completed + +Summary: + +- `pages/api/auth/[...nextauth].js` + - replaced: + - `await notifyClient.sendEmail(...).catch((error) => consoleLogger(error))` + - with explicit: + - `try { await notifyClient.sendEmail(...) } catch (error) { consoleLogger(error) }` +- preserved behavior contracts: + - Notify failures are still logged and do not throw through auth handler + - no changes to callback URL construction, locale/template selection, NextAuth options, session/cookies/pages config + +Validation: + +- `node tests/phase21/api-contract-slice1.test.cjs` -> pass + - helper: 4/4 + - file-handler: 53/53 + - email-handler: 12/12 + - endpoint-handler: 152/152 + - documents-handler: 3/3 + +Follow-ups: + +- Optional future auth hygiene (separate guarded slice): replace verbose auth `console.log` diagnostics with structured logger usage once production logging requirements are confirmed. diff --git a/pages/api/auth/[...nextauth].js b/pages/api/auth/[...nextauth].js index 75939546..7a713e47 100644 --- a/pages/api/auth/[...nextauth].js +++ b/pages/api/auth/[...nextauth].js @@ -139,8 +139,8 @@ const authOptions = (req, res) => { process.env.NOTIFY_API_KEY ); - await notifyClient - .sendEmail( + try { + await notifyClient.sendEmail( effectiveLocale === "cy" ? templateIdcy : templateId, @@ -149,8 +149,10 @@ const authOptions = (req, res) => { personalisation, reference } - ) - .catch((error) => consoleLogger(error)); + ); + } catch (error) { + consoleLogger(error); + } } }) ],