Skip to content

feat: integrate @zitadel/next-auth#57

Merged
mridang merged 37 commits into
mainfrom
feat/use-zitadel-auth
May 29, 2026
Merged

feat: integrate @zitadel/next-auth#57
mridang merged 37 commits into
mainfrom
feat/use-zitadel-auth

Conversation

@mridang
Copy link
Copy Markdown
Collaborator

@mridang mridang commented May 26, 2026

Description

Migrates this example to the published @zitadel/next-auth SDK, replacing the hand-rolled auth wiring with the SDK's factory pattern (handlers, getSession, signIn, signOut, signInUrl, signOutUrl). Switches the dependency from file:../next-auth to the npm-published version and aligns the /auth/login, /auth/error, and /profile routes with the rest of the SDK family.

Related Issue

N/A — part of the family-wide migration to the @zitadel/*-auth SDKs.

Motivation and Context

The example previously hand-rolled OIDC/PKCE wiring on top of @auth/core and pulled the SDK via a file: link. Both go away once @zitadel/next-auth is published: the example becomes a small consumer of the SDK and any consumer can copy it without local checkouts. This also brings the example's env vars (AUTH_URL, AUTH_SECRET, callback paths under /api/auth) in line with the other 7 example apps.

How Has This Been Tested?

Locally via devbox: npm run lint, npm run format:check, npm run prepack (typecheck), and npm run build all pass. Playwright E2E suite runs in CI. Manual smoke: full login → /profile → logout against a real Zitadel instance.

Documentation:

N/A — README updates for the new SDK shape landed in earlier commits on this branch.

Checklist:

  • I have updated the documentation accordingly.
  • I have assigned the correct milestone or created one if non-existent.
  • I have correctly labeled this pull request.
  • I have linked the corresponding issue in this description.
  • I have requested a review from at least 2 reviewers
  • I have checked the base branch of this pull request
  • I have checked my code for any possible security vulnerabilities

mridang added 29 commits May 12, 2026 11:26
- Move Session/JWT module augmentation from src/lib/auth.ts into a
  dedicated src/types/auth.d.ts so it is picked up across the project.
- Add tsconfig paths mapping @auth/core to ./node_modules/@auth/core
  to deduplicate the type identity (the SDK is linked via file: which
  otherwise loads two copies of @auth/core).
Replaces the hardcoded /auth/login (or /api/auth/signin/{provider})
URL with signInUrl({ redirectTo: ... }) from the SDK. The SDK builds
the URL from the configured basePath; the example no longer needs to
know where the sign-in page lives.
Converts /profile from a client component (useEffect + useSession +
client-side signIn) to a server component (await getSession +
redirect(signInUrl({ redirectTo: ... }))). Matches the server-side
gating pattern used by the other seven examples: no more flash of
the unauthenticated UI before the redirect kicks in.

The session lookup uses next/headers to build a Request from the
incoming cookie header for the SDK's getSession helper.
Two cleanups:

1. .env.example: remove NEXTAUTH_URL and NEXTAUTH_SECRET. These are
   NextAuth v4 legacy env var names; @auth/core v5 reads AUTH_URL /
   AUTH_SECRET. Grepped the source — nothing reads them.

2. SignOutButton.tsx: remove the 'use client' directive. The component
   is a pure HTML <form> with no event handlers, hooks, or state — it
   works as a server component. The directive was adding hydration
   weight for no functional reason.
The other examples (remix, sveltekit, tanstack) link the "Try signing
in again" button to /auth/login (the custom Auth.js sign-in page).
This example pointed at /api/auth/signin, which then redirected to
/auth/login anyway via pages.signIn config — same destination but an
extra hop. Drop the indirection so all 8 examples agree.
These were leftovers from the NextAuth v4 era; @auth/core v5 reads
AUTH_URL / AUTH_SECRET instead, which the test env already provides
via AUTH_URL. The dev server doesn't consume NEXTAUTH_* anywhere.
Aligns with example-remix-auth + example-tanstack-auth (and the
other 3 examples whose tsconfig was bumped to ES2022 in the same
sweep). Node 22 supports ES2022 natively so the build target
matches the deployment baseline.
Adds cross-platform install entries for native deps (@rollup,
@oxc-resolver, @oxc-parser) so 'npm ci' on Linux runners finds the
linux-x64-gnu binaries. The previous lockfile was generated on
darwin-arm64 only, omitting the Linux entries; CI hit npm/cli#4828
and refused to install them.

Regenerated via:
  npm install --include=optional --os=linux --cpu=x64 --package-lock-only
  npm install --include=optional
devbox is a local-only nix-based package manager; coupling it to the
devcontainer image (which already provides Node via the base image)
creates an unnecessary dependency for contributors using the
devcontainer. Remove the devbox feature and use plain npm ci /
playwright install instead.
The SDK is actually imported by app code, so knip detects it without the override.
@mridang mridang force-pushed the feat/use-zitadel-auth branch from 0c65161 to 594e0f8 Compare May 27, 2026 12:23
mridang added 8 commits May 27, 2026 15:46
The globals package was listed in devDeps but never imported.
It was hidden by 'globals' in knip ignoreDependencies, so the
unused-dep warning never surfaced. Uninstalling resolves both:
no more unused dep AND no more stale knip override.
Pin @auth/core to ^0.40.0 to match the SDK's range so npm dedupes to a
single copy (was pulling both 0.40 transitively and 0.41 directly).
Also drop the postcss override: Next 16 + Tailwind 4 resolve postcss
8.5.15 natively, well above the GHSA-7fh5-64p2-3v2j threshold (<8.4.31),
so the override is no longer doing anything.
Reverts the postcss override removal. Although the top-level postcss
resolves to a safe 8.5.15, removing the override let a nested
postcss@8.4.31 resurface (moderate XSS, GHSA-qx2v-qp2m-jg93). The
override force-bumps every postcss instance, not just the top-level
one, so it is load-bearing and must stay.
@mridang mridang merged commit 781d19a into main May 29, 2026
7 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.

1 participant