Skip to content

OUT-3578: add afterIfAvailable utility for non-request contexts#219

Merged
SandipBajracharya merged 1 commit intomasterfrom
OUT-3578
Apr 10, 2026
Merged

OUT-3578: add afterIfAvailable utility for non-request contexts#219
SandipBajracharya merged 1 commit intomasterfrom
OUT-3578

Conversation

@SandipBajracharya
Copy link
Copy Markdown
Collaborator

@SandipBajracharya SandipBajracharya commented Apr 10, 2026

Summary

  • Next.js after() throws when called outside a request scope (Trigger.dev background jobs, CLI scripts).
  • Added afterIfAvailable() utility that tries after() and falls back to direct async execution when no request context is available.
  • Applied to getQBPortalConnection()'s notification path in auth.service.ts, which runs in both Vercel serverless and Trigger.dev contexts.

Changes

File Change
src/app/api/core/utils/afterIfAvailable.ts New utility — tries after(), catches scope errors, falls back to direct execution with .catch() error logging
src/app/api/quickbooks/auth/auth.service.ts Use afterIfAvailable for IU notification in getQBPortalConnection; handleTokenExchange keeps after() (request-only)

Test plan

  • Trigger a refresh token expiry via Trigger.dev resyncFailedRecords task — verify notification fires without after() scope error
  • Trigger a refresh token expiry via Vercel serverless route — verify after() still defers the callback as before
  • Simulate notification failure in fallback path — verify error is logged via [afterIfAvailable] callback failed:

🤖 Generated with Claude Code

Next.js after() throws when called outside a request scope (Trigger.dev,
CLI scripts). Add afterIfAvailable() that tries after() and falls back
to direct execution. Use it in getQBPortalConnection's notification path
which runs in both Vercel serverless and Trigger.dev contexts.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@linear
Copy link
Copy Markdown

linear bot commented Apr 10, 2026

@vercel
Copy link
Copy Markdown

vercel bot commented Apr 10, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
quickbooks-sync Building Building Apr 10, 2026 10:23am
quickbooks-sync (dev) Ready Ready Preview, Comment Apr 10, 2026 10:23am

Request Review

@SandipBajracharya SandipBajracharya changed the title fix(OUT-3578): add afterIfAvailable utility for non-request contexts OUT-3578: add afterIfAvailable utility for non-request contexts Apr 10, 2026
Copy link
Copy Markdown
Collaborator

@priosshrsth priosshrsth left a comment

Choose a reason for hiding this comment

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

lgtm. Good to know. I have added after in all of repos as well.

@SandipBajracharya SandipBajracharya merged commit f1b9a29 into master Apr 10, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants