Skip to content

feat: add Descope authentication provider - #1113

Open
mariamantsurova wants to merge 6 commits into
AmanVarshney01:mainfrom
mariamantsurova:feat/add-descope-auth
Open

feat: add Descope authentication provider#1113
mariamantsurova wants to merge 6 commits into
AmanVarshney01:mainfrom
mariamantsurova:feat/add-descope-auth

Conversation

@mariamantsurova

@mariamantsurova mariamantsurova commented Jul 15, 2026

Copy link
Copy Markdown

Summary

Adds Descope as a selectable authentication provider, end-to-end: CLI schema/prompts/validation, template generator, generated auth templates (Next.js, React Router, TanStack Router), and docs-site coverage.

Changes

  • CLI & types: descope added to the Auth enum, prompts, compatibility-rules.ts, and config-validation.ts (supported frontends: Next.js / React Router / TanStack Router; not compatible with the Convex backend).
  • Templates: Descope auth templates for Next.js, React Router, and TanStack Router, plus dependency injection and post-install instructions. React Router wraps the app in <AuthProvider> and sets ssr: false (the SDK is client-only), which fixes a crash where useSession() ran outside the provider during SSR.
  • Docs site: Descope now appears in the stack builder (auth card, icon, and compatibility gating) and is documented in the CLI options/compatibility pages.

⚠️ Note for maintainer — Descope logo hosting

The Descope icon is currently bundled locally at apps/web/public/descope.svg (referenced as /descope.svg), because I don't have write access to the r2.better-t-stack.dev bucket that hosts every other icon.

If you'd prefer it served from R2 for consistency with the other icons, please upload it and switch the reference:

npx wrangler r2 object put "bucket/icons/descope.svg" \
  --file=apps/web/public/descope.svg --remote

Then in apps/web/src/lib/constant.ts change icon: "/descope.svg"icon: `${ICON_BASE_URL}/descope.svg` and delete the local file.

Testing

  • descope-matrix.test.ts (10/10) and web app tests (25/25) pass.
  • Full CLI test suite, oxlint, oxfmt --check, and bun build:cli all pass.
  • Verified a scaffolded React Router + Descope app builds and boots as a SPA.

Summary by CodeRabbit

  • New Features
    • Added Descope as a new CLI --auth option with generated sign-in/out pages, session handling, and protected auth flows for supported frontends (Next.js, React Router, TanStack Router), including ORPC/tRPC authorization wiring.
    • CLI “Next steps” now includes Descope-specific setup guidance and environment variable scaffolding.
  • Bug Fixes
    • Improved tech icon rendering for root-relative (/...) icon paths.
  • Documentation
    • Updated CLI docs and compatibility requirements to include Descope and its supported frontend/backend combinations.
  • Tests
    • Added a Descope compatibility and generation matrix test suite with negative cases.

@vercel

vercel Bot commented Jul 15, 2026

Copy link
Copy Markdown

@mariamantsurova is attempting to deploy a commit to the Better T Stack Team on Vercel.

A member of the Team first needs to authorize it.

@mariamantsurova
mariamantsurova force-pushed the feat/add-descope-auth branch from 1f52db2 to 61e3d1a Compare July 15, 2026 15:10
@coderabbitai

coderabbitai Bot commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

Walkthrough

Changes

Descope authentication is added to CLI selection and validation, generated frontend and API templates, environment schemas, dependency wiring, documentation, and matrix tests. Web icon components also update handling for root-relative icon paths.

Descope authentication

Layer / File(s) Summary
Provider selection and compatibility
packages/types/src/schemas.ts, apps/cli/src/prompts/auth.ts, apps/cli/src/utils/*, apps/web/src/app/(home)/new/_components/utils.ts, apps/web/src/lib/constant.ts, apps/cli/src/helpers/core/post-installation.ts, packages/template-generator/templates/packages/env/*, apps/web/content/docs/cli/*, apps/web/content/docs/index.mdx
Descope is added to auth configuration, CLI and web selection, compatibility validation, environment schemas, post-install instructions, and documentation.
Generated dependencies and providers
packages/template-generator/src/{processors,utils}/*, packages/template-generator/src/template-handlers/auth.ts, packages/template-generator/templates/frontend/react/*, packages/template-generator/templates/frontend/react/web-base/*, packages/template-generator/templates/auth/descope/convex/backend/*
Generated projects receive Descope SDK dependencies, frontend providers, Convex authentication configuration, client-only React Router configuration, private-data wiring, and authenticated navigation.
API session validation
packages/template-generator/templates/api/orpc/*, packages/template-generator/templates/api/trpc/*
Generated ORPC and tRPC contexts validate Descope bearer tokens, protected procedures require sessions, routers expose session user IDs, and clients attach authorization headers.
Generated authentication flows
packages/template-generator/templates/auth/descope/*/web/react/*
Next.js, React Router, and TanStack Router templates add Descope session gates, sign-in or sign-up flows, dashboards, API or Convex queries, session bridges, and sign-out actions.
Generation matrix validation
apps/cli/test/descope-matrix.test.ts
Matrix tests cover supported combinations, generated dependencies and wiring, frontend-specific artifacts, environment placement, API validation, Convex integration, and rejected unsupported configurations.

Web runtime safeguards

Layer / File(s) Summary
Root-relative icon handling
apps/web/src/app/(home)/new/_components/tech-icon.tsx, apps/web/src/components/ui/tech-badge.tsx
Icon components treat /-prefixed paths as valid icon sources.

Possibly related PRs

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title is concise and accurately summarizes the main change: adding Descope as an authentication provider.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@mariamantsurova

Copy link
Copy Markdown
Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jul 15, 2026

Copy link
Copy Markdown
Contributor
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 4

🧹 Nitpick comments (2)
packages/template-generator/templates/frontend/react/react-router/src/root.tsx.hbs (1)

22-29: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Consolidate the env import.

Similar to how you structured it in the tanstack-router template, you can consolidate the env import for both the Descope and Convex branches to prevent template duplication and make it cleaner.

♻️ Proposed refactor
-{{`#if` (eq auth "descope")}}
-import { AuthProvider } from "`@descope/react-sdk`";
-import { env } from "@{{projectName}}/env/web";
-{{/if}}
-
-{{`#if` (eq backend "convex")}}
-import { ConvexReactClient } from "convex/react";
-import { env } from "@{{projectName}}/env/web";
+{{`#if` (or (eq backend "convex") (eq auth "descope"))}}
+import { env } from "@{{projectName}}/env/web";
+{{/if}}
+
+{{`#if` (eq auth "descope")}}
+import { AuthProvider } from "`@descope/react-sdk`";
+{{/if}}
+
+{{`#if` (eq backend "convex")}}
+import { ConvexReactClient } from "convex/react";
packages/template-generator/src/utils/add-deps.ts (1)

29-33: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Consider removing unused @descope/react-native-sdk.

This SDK is mapped in dependencyVersionMap, but unlike Clerk or Better-Auth, there is no corresponding injection logic for it inside processStandardAuthDeps (in auth-deps.ts), nor are there any native post-install instructions.

If Descope support for React Native / Expo is deferred or not supported in this PR, consider removing this entry to avoid dead code and confusion.


ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 22a0cd4c-b944-42d2-9384-e3d6f245e35c

📥 Commits

Reviewing files that changed from the base of the PR and between 64be4ce and 61e3d1a.

⛔ Files ignored due to path filters (2)
  • apps/web/public/descope.svg is excluded by !**/*.svg
  • packages/template-generator/src/templates.generated.ts is excluded by !**/*.generated.*
📒 Files selected for processing (38)
  • apps/cli/src/helpers/core/post-installation.ts
  • apps/cli/src/prompts/auth.ts
  • apps/cli/src/utils/compatibility-rules.ts
  • apps/cli/src/utils/config-validation.ts
  • apps/cli/test/descope-matrix.test.ts
  • apps/web/content/docs/cli/compatibility.mdx
  • apps/web/content/docs/cli/index.mdx
  • apps/web/content/docs/cli/options.mdx
  • apps/web/content/docs/index.mdx
  • apps/web/src/app/(home)/new/_components/tech-icon.tsx
  • apps/web/src/app/(home)/new/_components/utils.ts
  • apps/web/src/components/providers.tsx
  • apps/web/src/components/ui/tech-badge.tsx
  • apps/web/src/lib/constant.ts
  • packages/template-generator/src/processors/auth-deps.ts
  • packages/template-generator/src/utils/add-deps.ts
  • packages/template-generator/templates/api/orpc/server/src/context.ts.hbs
  • packages/template-generator/templates/api/orpc/server/src/index.ts.hbs
  • packages/template-generator/templates/api/orpc/web/react/base/src/utils/orpc.ts.hbs
  • packages/template-generator/templates/api/trpc/server/src/context.ts.hbs
  • packages/template-generator/templates/api/trpc/server/src/index.ts.hbs
  • packages/template-generator/templates/api/trpc/server/src/routers/index.ts.hbs
  • packages/template-generator/templates/api/trpc/web/react/base/src/utils/trpc.ts.hbs
  • packages/template-generator/templates/auth/descope/web/react/base/src/utils/descope-auth.ts.hbs
  • packages/template-generator/templates/auth/descope/web/react/next/src/app/dashboard/page.tsx.hbs
  • packages/template-generator/templates/auth/descope/web/react/next/src/app/sign-in/page.tsx.hbs
  • packages/template-generator/templates/auth/descope/web/react/next/src/proxy.ts.hbs
  • packages/template-generator/templates/auth/descope/web/react/react-router/src/routes/dashboard.tsx.hbs
  • packages/template-generator/templates/auth/descope/web/react/tanstack-router/src/routes/_auth/dashboard.tsx.hbs
  • packages/template-generator/templates/auth/descope/web/react/tanstack-router/src/routes/_auth/route.tsx.hbs
  • packages/template-generator/templates/frontend/react/next/src/app/layout.tsx.hbs
  • packages/template-generator/templates/frontend/react/react-router/react-router.config.ts.hbs
  • packages/template-generator/templates/frontend/react/react-router/src/root.tsx.hbs
  • packages/template-generator/templates/frontend/react/tanstack-router/src/main.tsx.hbs
  • packages/template-generator/templates/frontend/react/web-base/src/components/header.tsx.hbs
  • packages/template-generator/templates/packages/env/src/server.ts.hbs
  • packages/template-generator/templates/packages/env/src/web.ts.hbs
  • packages/types/src/schemas.ts

Comment thread apps/cli/test/descope-matrix.test.ts
Comment thread apps/web/src/components/providers.tsx Outdated
Comment thread apps/web/src/components/providers.tsx Outdated
@mariamantsurova
mariamantsurova force-pushed the feat/add-descope-auth branch from 1d70fd8 to ba0e611 Compare July 15, 2026 18:16
Add Descope as a selectable auth provider across the CLI, template
generator, and docs site.

CLI & templates:
- Add `descope` to the Auth schema, prompts, compatibility rules, and
  config validation (Next.js, React Router, TanStack Router; not Convex).
- Add Descope auth templates for Next.js, React Router, and TanStack
  Router, plus dependency injection and post-install instructions.
- React Router: wrap the app in `<AuthProvider>` and set `ssr: false`
  (the SDK is client-only), fixing a crash where `useSession()` ran
  outside the provider during SSR.

Docs site:
- Surface Descope in the stack builder (auth card + icon + compatibility
  gating) and document it in the CLI options/compatibility pages.
- Bundle the official Descope logo at apps/web/public/descope.svg.
@mariamantsurova
mariamantsurova force-pushed the feat/add-descope-auth branch from ba0e611 to 123b843 Compare July 15, 2026 18:36

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
apps/cli/src/utils/compatibility-rules.ts (1)

238-243: 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Allow "none" as a compatible frontend to match validation logic.

Currently, isFrontendAllowedWithBackend rejects "none" for Descope, meaning users who pre-select --auth descope cannot choose "None" in the frontend prompt. However, validateBackendConstraints explicitly allows config.frontend === ["none"] for Descope (via f !== "none").

Add "none" to this list to ensure consistency across the CLI, matching how Clerk handles frontend validation.

💡 Proposed fix
   if (auth === "descope") {
     // Descope supports these frontends across all backends, including Convex.
-    const compatibleFrontends = ["react-router", "tanstack-router", "next"];
+    const compatibleFrontends = ["react-router", "tanstack-router", "next", "none"];
     if (!compatibleFrontends.includes(frontend)) return false;
   }
🧹 Nitpick comments (1)
apps/cli/test/descope-matrix.test.ts (1)

264-275: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Reuse the shared SDK/env-var helpers instead of re-deriving the mapping inline.

This block re-implements the frontend→SDK-package and frontend→public-env-var mapping with a raw frontend === "next" ternary, duplicating logic that the shared helpers (added earlier in this file for the main matrix) already encode. If that mapping ever changes for one of the frontends, this Convex-specific block could silently diverge from the matrix test's expectations.

♻️ Suggested approach
-      if (frontend === "next") {
-        expect(files.get("apps/web/package.json")).toContain("`@descope/nextjs-sdk`");
-        expect(files.get("packages/env/src/web.ts")).toContain("NEXT_PUBLIC_DESCOPE_PROJECT_ID");
-      } else {
-        expect(files.get("apps/web/package.json")).toContain("`@descope/react-sdk`");
-        const webEnv = files.get("packages/env/src/web.ts");
-        expect(webEnv).toContain("VITE_DESCOPE_PROJECT_ID");
-        expect(webEnv).toContain('typeof process !== "undefined"');
-      }
+      expect(files.get("apps/web/package.json")).toContain(getExpectedDescopeSdkPackage(frontend));
+      const webEnv = files.get("packages/env/src/web.ts");
+      expect(webEnv).toContain(getExpectedPublicEnvVarName(frontend));
+      if (frontend !== "next") {
+        expect(webEnv).toContain('typeof process !== "undefined"');
+      }

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 96c1733f-e1c0-4f98-912f-8045eb12aa66

📥 Commits

Reviewing files that changed from the base of the PR and between 123b843 and c2272f1.

⛔ Files ignored due to path filters (1)
  • packages/template-generator/src/templates.generated.ts is excluded by !**/*.generated.*
📒 Files selected for processing (24)
  • apps/cli/src/helpers/core/post-installation.ts
  • apps/cli/src/prompts/auth.ts
  • apps/cli/src/utils/compatibility-rules.ts
  • apps/cli/src/utils/config-validation.ts
  • apps/cli/test/descope-matrix.test.ts
  • apps/web/content/docs/cli/compatibility.mdx
  • apps/web/content/docs/cli/options.mdx
  • apps/web/src/app/(home)/new/_components/utils.ts
  • packages/template-generator/src/processors/auth-deps.ts
  • packages/template-generator/src/template-handlers/auth.ts
  • packages/template-generator/templates/auth/descope/convex/backend/convex/auth.config.ts.hbs
  • packages/template-generator/templates/auth/descope/convex/backend/convex/privateData.ts.hbs
  • packages/template-generator/templates/auth/descope/convex/web/react/next/src/app/dashboard/page.tsx.hbs
  • packages/template-generator/templates/auth/descope/convex/web/react/next/src/app/sign-in/page.tsx.hbs
  • packages/template-generator/templates/auth/descope/convex/web/react/next/src/utils/convex-descope-auth.ts.hbs
  • packages/template-generator/templates/auth/descope/convex/web/react/react-router/src/routes/dashboard.tsx.hbs
  • packages/template-generator/templates/auth/descope/convex/web/react/react-router/src/utils/convex-descope-auth.ts.hbs
  • packages/template-generator/templates/auth/descope/convex/web/react/tanstack-router/src/routes/_auth/dashboard.tsx.hbs
  • packages/template-generator/templates/auth/descope/convex/web/react/tanstack-router/src/routes/_auth/route.tsx.hbs
  • packages/template-generator/templates/auth/descope/convex/web/react/tanstack-router/src/utils/convex-descope-auth.ts.hbs
  • packages/template-generator/templates/frontend/react/next/src/components/providers.tsx.hbs
  • packages/template-generator/templates/frontend/react/react-router/src/root.tsx.hbs
  • packages/template-generator/templates/frontend/react/tanstack-router/src/main.tsx.hbs
  • packages/template-generator/templates/packages/env/src/web.ts.hbs
🚧 Files skipped from review as they are similar to previous changes (1)
  • apps/cli/src/helpers/core/post-installation.ts

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