Skip to content

feat(auth): Kratos-only dashboard (drop Auth.js), same-origin + preview-capable#427

Draft
huv1k wants to merge 1 commit into
mainfrom
huv1k/kratos-only-auth
Draft

feat(auth): Kratos-only dashboard (drop Auth.js), same-origin + preview-capable#427
huv1k wants to merge 1 commit into
mainfrom
huv1k/kratos-only-auth

Conversation

@huv1k

@huv1k huv1k commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

What

Makes the dashboard Kratos-only and removes Auth.js (NextAuth). main already shipped the @ory/nextjs same-origin Elements UI (/login, /registration, /recovery, /verification + SDK proxy) behind a flag, but sessions were still managed by Auth.js. This finishes the migration. The backend contract is unchanged — a Hydra JWT is still sent as Authorization: Bearer, now minted server-side.

Key changes

  • Session: getServerSession() (Kratos whoami) replaces the Auth.js JWT; the middleware gate uses an edge-safe whoami; tRPC no longer threads an Auth.js session through context.
  • Backend token: minted server-side from the Kratos session via the silent grant (no user-facing OAuth redirect), and cached across requests keyed by the validated session id — the live session is always re-validated first and tokens stay server-only.
  • Entry/UI: the custom-UI flag gate is removed (Kratos is unconditional); legacy /sign-in, /sign-up, /forgot-password redirect to the same-origin flow pages.
  • Logout: Kratos getLogoutFlow().
  • Removed: src/auth.ts, next-auth.d.ts, the authjs-* / oauth* helpers and routes, the next-auth dependency.

Env

  • Add: ORY_OAUTH2_REDIRECT_URI (optional; defaults to https://${NEXT_PUBLIC_E2B_DOMAIN}/api/auth/oauth/callback/ory).
  • Remove: AUTH_SECRET, AUTH_TRUST_HOST, AUTH_COOKIE_PREFIX, NEXT_PUBLIC_ORY_CUSTOM_UI.
  • NEXT_PUBLIC_ORY_SDK_URL — Kratos public URL (= ORY_SDK_URL on Ory Network).

Because the custom-UI gate is gone, the enable_custom_auth_ui terraform toggle no longer gates dashboard auth.

Verification

build, lint, biome check, and the full unit + integration suite pass (incl. backend-token cache tests). Runtime auth needs preview verification against live Ory (Preview Tests job + SDK-URL env vars).

Follow-ups (not in this PR)

  • First login pays one cold silent-grant mint (~3–4s); reducible by marking the OAuth2 client skip_consent (Ory config, no code change).
  • No Kratos /settings flow page yet (account settings use admin APIs at /dashboard/account).

@cla-bot cla-bot Bot added the cla-signed label Jun 17, 2026
@vercel

vercel Bot commented Jun 17, 2026

Copy link
Copy Markdown

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

Project Deployment Actions Updated (UTC)
web Ready Ready Preview, Comment Jun 17, 2026 4:32pm

Request Review

Comment thread scripts/spike-silent-oauth-grant.ts Fixed
Comment thread scripts/spike-silent-oauth-grant.ts Fixed
Comment thread src/features/dashboard/sidebar/menu.tsx Fixed
Comment thread src/features/dashboard/sidebar/menu.tsx Fixed
huv1k added a commit that referenced this pull request Jun 17, 2026
Re-applies PR #427's Kratos-only auth on top of current main, which had moved to
the @ory/nextjs same-origin Elements flow (pages, SDK proxy, config) but still
managed sessions through Auth.js. This removes Auth.js entirely:

- Read the session via @ory/nextjs getServerSession() and mint the backend Hydra
  access token server-side from the Kratos session (silent grant); no
  user-facing OAuth2 bounce (preview-friendly).
- Proxy auth gate checks a real Kratos session via /sessions/whoami instead of
  the Auth.js middleware; the Ory SDK proxy always runs (drop NEXT_PUBLIC_ORY_CUSTOM_UI gate).
- Logout uses the Kratos self-service logout flow (getLogoutFlow).
- tRPC no longer threads an Auth.js session through context.
- Legacy /sign-in, /sign-up, /forgot-password redirect to the same-origin Kratos
  flow pages (/login, /registration, /recovery).
- Remove src/auth.ts, next-auth.d.ts, all authjs-*/oauth/* machinery, the
  next-auth dependency, and AUTH_SECRET/AUTH_TRUST_HOST/AUTH_COOKIE_PREFIX env
  vars; add ORY_OAUTH2_REDIRECT_URI for the silent-grant redirect_uri.

Tests updated/removed for dropped Auth.js paths; build, biome check, and the
unit + integration suites pass.
@huv1k huv1k force-pushed the huv1k/kratos-only-auth branch from 83afe4c to e23fc30 Compare June 17, 2026 14:59
@huv1k huv1k force-pushed the huv1k/kratos-only-auth branch from d963710 to 1b6fc9b Compare June 17, 2026 16:17
Make Kratos the only auth path and remove Auth.js (NextAuth). main already
shipped the @ory/nextjs same-origin Elements UI behind a flag but still managed
sessions via Auth.js; this completes the migration:

- Sessions via getServerSession() (Kratos whoami); the backend Hydra JWT is
  minted server-side from the session (silent grant), no user-facing redirect.
- Middleware auth gate uses an edge-safe whoami; tRPC no longer threads an
  Auth.js session through context.
- Legacy /sign-in, /sign-up, /forgot-password redirect to the same-origin
  /login, /registration, /recovery pages; the custom-UI flag gate is removed.
- Logout via Kratos getLogoutFlow().
- Cache the minted backend token across requests, keyed by the validated Kratos
  session id (+ subject) and reused until just before expiry; the live session
  is always re-validated first and tokens stay server-only.

Removes src/auth.ts, next-auth.d.ts, the authjs-*/oauth* helpers and routes, the
next-auth dependency, and the AUTH_SECRET/AUTH_TRUST_HOST/AUTH_COOKIE_PREFIX/
NEXT_PUBLIC_ORY_CUSTOM_UI env vars; adds ORY_OAUTH2_REDIRECT_URI.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants