feat: add Descope authentication provider - #1113
Conversation
|
@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. |
1f52db2 to
61e3d1a
Compare
|
Note Reviews pausedIt 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 Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
WalkthroughChangesDescope 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
Web runtime safeguards
Possibly related PRs
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
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. Comment |
|
@coderabbitai review |
✅ Action performedReview finished.
|
There was a problem hiding this comment.
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 valueConsolidate the
envimport.Similar to how you structured it in the
tanstack-routertemplate, you can consolidate theenvimport 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 valueConsider 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 insideprocessStandardAuthDeps(inauth-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
⛔ Files ignored due to path filters (2)
apps/web/public/descope.svgis excluded by!**/*.svgpackages/template-generator/src/templates.generated.tsis excluded by!**/*.generated.*
📒 Files selected for processing (38)
apps/cli/src/helpers/core/post-installation.tsapps/cli/src/prompts/auth.tsapps/cli/src/utils/compatibility-rules.tsapps/cli/src/utils/config-validation.tsapps/cli/test/descope-matrix.test.tsapps/web/content/docs/cli/compatibility.mdxapps/web/content/docs/cli/index.mdxapps/web/content/docs/cli/options.mdxapps/web/content/docs/index.mdxapps/web/src/app/(home)/new/_components/tech-icon.tsxapps/web/src/app/(home)/new/_components/utils.tsapps/web/src/components/providers.tsxapps/web/src/components/ui/tech-badge.tsxapps/web/src/lib/constant.tspackages/template-generator/src/processors/auth-deps.tspackages/template-generator/src/utils/add-deps.tspackages/template-generator/templates/api/orpc/server/src/context.ts.hbspackages/template-generator/templates/api/orpc/server/src/index.ts.hbspackages/template-generator/templates/api/orpc/web/react/base/src/utils/orpc.ts.hbspackages/template-generator/templates/api/trpc/server/src/context.ts.hbspackages/template-generator/templates/api/trpc/server/src/index.ts.hbspackages/template-generator/templates/api/trpc/server/src/routers/index.ts.hbspackages/template-generator/templates/api/trpc/web/react/base/src/utils/trpc.ts.hbspackages/template-generator/templates/auth/descope/web/react/base/src/utils/descope-auth.ts.hbspackages/template-generator/templates/auth/descope/web/react/next/src/app/dashboard/page.tsx.hbspackages/template-generator/templates/auth/descope/web/react/next/src/app/sign-in/page.tsx.hbspackages/template-generator/templates/auth/descope/web/react/next/src/proxy.ts.hbspackages/template-generator/templates/auth/descope/web/react/react-router/src/routes/dashboard.tsx.hbspackages/template-generator/templates/auth/descope/web/react/tanstack-router/src/routes/_auth/dashboard.tsx.hbspackages/template-generator/templates/auth/descope/web/react/tanstack-router/src/routes/_auth/route.tsx.hbspackages/template-generator/templates/frontend/react/next/src/app/layout.tsx.hbspackages/template-generator/templates/frontend/react/react-router/react-router.config.ts.hbspackages/template-generator/templates/frontend/react/react-router/src/root.tsx.hbspackages/template-generator/templates/frontend/react/tanstack-router/src/main.tsx.hbspackages/template-generator/templates/frontend/react/web-base/src/components/header.tsx.hbspackages/template-generator/templates/packages/env/src/server.ts.hbspackages/template-generator/templates/packages/env/src/web.ts.hbspackages/types/src/schemas.ts
1d70fd8 to
ba0e611
Compare
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.
ba0e611 to
123b843
Compare
There was a problem hiding this comment.
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 winAllow
"none"as a compatible frontend to match validation logic.Currently,
isFrontendAllowedWithBackendrejects"none"for Descope, meaning users who pre-select--auth descopecannot choose "None" in the frontend prompt. However,validateBackendConstraintsexplicitly allowsconfig.frontend === ["none"]for Descope (viaf !== "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 winReuse 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
⛔ Files ignored due to path filters (1)
packages/template-generator/src/templates.generated.tsis excluded by!**/*.generated.*
📒 Files selected for processing (24)
apps/cli/src/helpers/core/post-installation.tsapps/cli/src/prompts/auth.tsapps/cli/src/utils/compatibility-rules.tsapps/cli/src/utils/config-validation.tsapps/cli/test/descope-matrix.test.tsapps/web/content/docs/cli/compatibility.mdxapps/web/content/docs/cli/options.mdxapps/web/src/app/(home)/new/_components/utils.tspackages/template-generator/src/processors/auth-deps.tspackages/template-generator/src/template-handlers/auth.tspackages/template-generator/templates/auth/descope/convex/backend/convex/auth.config.ts.hbspackages/template-generator/templates/auth/descope/convex/backend/convex/privateData.ts.hbspackages/template-generator/templates/auth/descope/convex/web/react/next/src/app/dashboard/page.tsx.hbspackages/template-generator/templates/auth/descope/convex/web/react/next/src/app/sign-in/page.tsx.hbspackages/template-generator/templates/auth/descope/convex/web/react/next/src/utils/convex-descope-auth.ts.hbspackages/template-generator/templates/auth/descope/convex/web/react/react-router/src/routes/dashboard.tsx.hbspackages/template-generator/templates/auth/descope/convex/web/react/react-router/src/utils/convex-descope-auth.ts.hbspackages/template-generator/templates/auth/descope/convex/web/react/tanstack-router/src/routes/_auth/dashboard.tsx.hbspackages/template-generator/templates/auth/descope/convex/web/react/tanstack-router/src/routes/_auth/route.tsx.hbspackages/template-generator/templates/auth/descope/convex/web/react/tanstack-router/src/utils/convex-descope-auth.ts.hbspackages/template-generator/templates/frontend/react/next/src/components/providers.tsx.hbspackages/template-generator/templates/frontend/react/react-router/src/root.tsx.hbspackages/template-generator/templates/frontend/react/tanstack-router/src/main.tsx.hbspackages/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
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
descopeadded to the Auth enum, prompts,compatibility-rules.ts, andconfig-validation.ts(supported frontends: Next.js / React Router / TanStack Router; not compatible with the Convex backend).<AuthProvider>and setsssr: false(the SDK is client-only), which fixes a crash whereuseSession()ran outside the provider during SSR.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 ther2.better-t-stack.devbucket 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 --remoteThen in
apps/web/src/lib/constant.tschangeicon: "/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.oxlint,oxfmt --check, andbun build:cliall pass.Summary by CodeRabbit
--authoption 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./...) icon paths.