Skip to content

Conversation

@shineli1984
Copy link
Collaborator

@shineli1984 shineli1984 commented Dec 17, 2025

Summary

Adding auth-nextjs for convenient integration with nextjs + SSR.


Note

Introduces first-class Next.js (Auth.js v5) support with client/server packages, SSR-safe token handling, and sample app integration.

  • New packages: @imtbl/auth-next-client (provider, hooks, CallbackPage, hydration helpers) and @imtbl/auth-next-server (createImmutableAuth/createAuthConfig, JWT/session callbacks, middleware/utilities, constants/types)
  • Token lifecycle: Client syncs refreshed tokens to NextAuth via AuthEvents.TOKEN_REFRESHED; server marks expired tokens (no server-side refresh) to avoid race conditions; robust JWT/session shaping
  • Auth SDK updates: Emits TOKEN_REFRESHED and USER_REMOVED events; refined refresh error handling; new tests for refresh flows
  • Sample app: Adds NextAuth API routes per env, wraps app with ImmutableAuthProvider, adds OAuth callback page and demo component; Next.js config supports toggling API routes
  • Repo/config tweaks: Increase NODE_OPTIONS, serialize network concurrency in .npmrc, relax syncpack peer ranges; widespread dev dep bumps (swc, jest, eslint, types/node, next)

Written by Cursor Bugbot for commit bd230a1. This will update automatically on new commits. Configure here.

@shineli1984 shineli1984 requested a review from a team as a code owner December 17, 2025 01:09
@socket-security
Copy link

socket-security bot commented Dec 17, 2025

Warning

Review the following alerts detected in dependencies.

According to your organization's Security Policy, it is recommended to resolve "Warn" alerts. Learn more about Socket for GitHub.

Action Severity Alert  (click "▶" to expand/collapse)
Warn High
HTTP dependency: npm @imtbl/contracts depends on https://github.com/immutable/seaport.git#1.6.0+im4

Dependency: seaport-16@https://github.com/immutable/seaport.git#1.6.0+im4

Location: Package overview

From: examples/contracts/package.jsonnpm/@imtbl/contracts@2.2.18

ℹ Read more on: This package | This alert | What are http dependencies?

Next steps: Take a moment to review the security alert above. Review the linked package source code to understand the potential risk. Ensure the package is not malicious before proceeding. If you're unsure how to proceed, reach out to your security team or ask the Socket team for help at support@socket.dev.

Suggestion: Publish the HTTP URL dependency to a public or private package repository and consume it from there.

Mark the package as acceptable risk. To ignore this alert only in this pull request, reply with the comment @SocketSecurity ignore npm/@imtbl/contracts@2.2.18. You can also ignore all packages with @SocketSecurity ignore-all. To ignore an alert for all future pull requests, use Socket's Dashboard to change the triage state of this alert.

Warn High
HTTP dependency: npm @imtbl/contracts depends on https://github.com/immutable/seaport-core.git#1.6.0+im2

Dependency: seaport-core-16@https://github.com/immutable/seaport-core.git#1.6.0+im2

Location: Package overview

From: examples/contracts/package.jsonnpm/@imtbl/contracts@2.2.18

ℹ Read more on: This package | This alert | What are http dependencies?

Next steps: Take a moment to review the security alert above. Review the linked package source code to understand the potential risk. Ensure the package is not malicious before proceeding. If you're unsure how to proceed, reach out to your security team or ask the Socket team for help at support@socket.dev.

Suggestion: Publish the HTTP URL dependency to a public or private package repository and consume it from there.

Mark the package as acceptable risk. To ignore this alert only in this pull request, reply with the comment @SocketSecurity ignore npm/@imtbl/contracts@2.2.18. You can also ignore all packages with @SocketSecurity ignore-all. To ignore an alert for all future pull requests, use Socket's Dashboard to change the triage state of this alert.

View full report

Copy link
Contributor

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

This PR is being reviewed by Cursor Bugbot

Details

Your team is on the Bugbot Free tier. On this plan, Bugbot will review limited PRs each billing cycle for each member of your team.

To receive Bugbot reviews on all of your PRs, visit the Cursor dashboard to activate Pro and start your 14-day free trial.

@nx-cloud
Copy link

nx-cloud bot commented Dec 17, 2025

View your CI Pipeline Execution ↗ for commit bd230a1

Command Status Duration Result
nx release publish --tag alpha ✅ Succeeded 46s View ↗
nx run-many -p @imtbl/sdk,@imtbl/checkout-widge... ✅ Succeeded 2m 26s View ↗

☁️ Nx Cloud last updated this comment at 2026-01-16 04:12:43 UTC

@nx-cloud
Copy link

nx-cloud bot commented Dec 17, 2025

🤖 Nx Cloud AI Fix Eligible

An automatically generated fix could have helped fix failing tasks for this run, but Self-healing CI is disabled for this workspace. Visit workspace settings to enable it and get automatic fixes in future runs.

To disable these notifications, a workspace admin can disable them in workspace settings.


View your CI Pipeline Execution ↗ for commit e9cfdc4

Command Status Duration Result
nx affected -t build,lint,test ❌ Failed 3m 12s View ↗
nx run-many -p @imtbl/sdk,@imtbl/checkout-widge... ✅ Succeeded 3s View ↗

☁️ Nx Cloud last updated this comment at 2025-12-17 04:04:32 UTC

} finally {
setIsLoading(false);
}
}, [fetcher, getAccessToken]);
Copy link
Contributor

Choose a reason for hiding this comment

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

Missing fetch cancellation causes stale data race condition

Medium Severity

The useHydratedData hook has a race condition where in-flight fetches are not cancelled when props change. When props change from ssr: false to ssr: true (e.g., during soft navigation after token refresh), the props-sync effect correctly sets the fresh serverData. However, the previously started client-side fetch continues running and when it completes, setData(result) overwrites the correct server data with stale results. There's no AbortController, fetch ID tracking, or staleness check to prevent this.

Additional Locations (1)

Fix in Cursor Fix in Web


hasFetchedRef.current = true;
fetchData();
}, [needsClientFetch, ssr, auth, fetchData]);
Copy link
Contributor

Choose a reason for hiding this comment

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

Client fetch fails when session not yet loaded

Medium Severity

When ssr=true but fetchError exists (server-side fetch failed), useHydratedData immediately attempts a client-side retry without waiting for the session to load from useSession(). The guard if (!ssr && !auth) return only waits for auth when ssr=false, but when ssr=true with a fetchError, it proceeds immediately. If useSession() is still in 'loading' state, getAccessToken() will throw "No access token available" because session is undefined. After this error, hasFetchedRef.current remains true, blocking retries even after the session loads.

Fix in Cursor Fix in Web

console.warn('[auth-next-client] Logout cleanup error:', error);
}
}
}, [auth]);
Copy link
Contributor

Choose a reason for hiding this comment

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

Double signOut calls during logout flow

Medium Severity

The handleSignOut function calls signOut() from NextAuth, then calls auth.getLogoutUrl(). However, getLogoutUrl() emits the LOGGED_OUT event, which triggers the handleLoggedOut listener that also calls signOut(). This results in NextAuth's signOut being invoked twice during a single logout operation, causing redundant work and potential race conditions if the first signOut hasn't completed.

Additional Locations (1)

Fix in Cursor Fix in Web

// No auth instance, just sign out from NextAuth directly
await signOut({ redirect: false });
}
}, [auth]);
Copy link
Contributor

Choose a reason for hiding this comment

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

Sign out returns before NextAuth session is cleared

Medium Severity

The handleSignOut function returns before NextAuth signOut() completes in the success path. When auth.getLogoutUrl() emits the LOGGED_OUT event, the handleLoggedOut listener calls signOut() asynchronously, but TypedEventEmitter.emit() doesn't await async handlers. This creates a race condition where code awaiting handleSignOut() may execute while the NextAuth session cookie still exists. The error and no-auth paths correctly await signOut(), making this behavior inconsistent.

Fix in Cursor Fix in Web

}
},
"scripts": {
"build": "tsup && pnpm build:types",
Copy link
Contributor

Choose a reason for hiding this comment

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

Missing build:types script causes build failure

High Severity

The build script references pnpm build:types but no build:types script is defined in the package. The package defines typegen for type generation. Comparing with @imtbl/auth-next-server which correctly uses "build": "pnpm transpile && pnpm typegen", this appears to be a typo where build:types should be typegen.

Fix in Cursor Fix in Web

// No auth instance, just sign out from NextAuth directly
await signOut({ redirect: false });
}
}, [auth]);
Copy link
Contributor

Choose a reason for hiding this comment

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

SignOut doesn't await NextAuth session clearance completion

Medium Severity

The handleSignOut function returns before NextAuth signOut() actually completes. It relies on getLogoutUrl() emitting a LOGGED_OUT event that triggers an async handleLoggedOut handler calling signOut(). However, TypedEventEmitter.emit() invokes handlers synchronously without awaiting their Promises. This causes callers who await handleSignOut() to receive a resolved Promise while the actual session cookie deletion is still in progress, leading to race conditions and potentially inconsistent authentication state.

Additional Locations (1)

Fix in Cursor Fix in Web

@shineli1984 shineli1984 deleted the auth-nextjs branch January 16, 2026 04:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants