| name | stytch-to-descope |
| description | Use this skill whenever anyone asks about migrating from Stytch to Descope โ whether they're a developer doing it themselves or a technical lead evaluating the move. Triggers on: "how do I migrate from Stytch", "replace Stytch with Descope", "we're moving off Stytch", "Stytch to Descope", "switch from Stytch", "our app uses stytch / @stytch/nextjs / Stytch UI / Stytch SSO / Connected Apps / SCIM and we want to use Descope instead", or any question about Stytch features (Consumer authentication, Multi-tenant / B2B Authentication, Enterprise SSO, SCIM, Admin Portal, M2M Authentication, Connected Apps, Session Management, Fraud & Risk) in the context of Descope. Works for any language or framework with a Descope SDK. Always use this skill before producing migration guidance โ do not rely on memory alone.
|
Stytch โ Descope Migration Skill
This skill guides self-service migrations from Stytch to Descope. It runs in three parts:
- MCP Check โ confirm whether the Descope MCP Server is available and suggest installing it if not
- Migration Plan โ gather context via triage questions, analyze the codebase's auth touchpoints, and produce a human-readable
MIGRATION-PLAN.md for the user to review
- Execution โ if the user confirms they want to proceed, execute the plan
Do not collapse these parts or skip ahead. The plan must be reviewed before code changes begin. If the file view is truncated, partial, or cut off, continue reading with the appropriate offset until all lines have been loaded; do not proceed based on a partial read.
Stytch is not only an authentication provider โ it is a broader identity platform spanning consumer authentication, multi-tenant/B2B authentication, organizations and members, enterprise SSO, SCIM, RBAC, JIT provisioning, MFA, session management, Admin Portal flows, fraud and risk protection, device fingerprinting, Protected Auth, machine-to-machine authentication, trusted auth tokens, and Connected Apps for OAuth/OIDC-based integrations and AI-agent access. A good migration first identifies which Stytch product surfaces are in use, then maps each one to the closest target feature or migration pattern. Expect Stytch migrations to vary more widely than a purely B2B auth migration, since a Stytch implementation may include consumer passwordless auth, enterprise-readiness features, fraud/risk infrastructure, and OAuth/OIDC connected-app workflows.
Primary references (both in this skill's directory):
references/implementation-nuances.md โ verified migration patterns for each framework, Stytch feature-to-Descope mappings, and known gotchas
references/flows-and-widgets.md โ Descope terminology/lingo, Flow structure and templates, Widgets, SSO Setup Suite, Console-vs-code decision guide
Guiding Principles
Console-first. Before recommending SDK code for any user-facing auth feature, check whether the Console, a Flow, a Widget, or the SSO Setup Suite covers the use case. Engineers integrate once (SDK setup + session validation). All subsequent auth evolution โ new methods, MFA changes, UI updates, tenant SSO onboarding โ should happen in the Console without code deployments. See references/flows-and-widgets.md โ Console vs. Code.
Ask, don't assume. At any design decision point โ Flow vs. custom code, Widget vs. custom page, MFA inline vs. separate enrollment, programmatic SSO vs. SSO Setup Suite, one-Organization-to-one-Tenant mapping โ use AskUserQuestion rather than proceeding with an assumption. The cost of a wrong assumption compounds across 20+ files, and the Stytch Organization โ Descope Tenant mapping in particular ripples into SSO, SCIM, RBAC, and domain routing. Uncertainty about architecture or intent is always worth a question.
MCP over memory. When the Descope MCP Server is available (confirmed in Part 1), use docs_ask_question to verify every SDK method name, option shape, and return type before writing it. Do not fall back to "verify the exact method name in the SDK type declarations" as a hedge โ just verify it directly.
Part 1: MCP Check (BLOCKING)
Before doing anything else, check whether the Descope Docs MCP is available by calling
search-descope-docs with a simple query (e.g., "session validation").
If the tool is available: proceed to Part 2 immediately.
If the tool is not available, show this message and use AskUserQuestion to ask whether
they want to install it first:
Descope Docs MCP is not installed.
This skill uses the Descope Docs MCP to look up current API signatures, SDK methods, and
feature availability during migration. Without it, guidance is based on static training data,
which may be stale and can produce SDK calls that don't exist.
You can install it in a few minutes at https://docs-mcp.descope.com/ (server URL:
https://docs-mcp.descope.com/mcp). It significantly improves the accuracy of the
migration output โ especially for SDK lookups and flow-specific configuration.
Would you like to install the MCP before we continue, or proceed without it?
- If they choose to install: pause and wait. Once they confirm it's installed, re-check by calling
search-descope-docs again before proceeding.
- If they choose to proceed without it: continue, but flag any SDK-specific answers as "based on last known documentation โ verify against the current SDK."
Do not proceed to Part 2 until this step is resolved.
Part 2: Migration Plan
Part 2 has two sub-steps:
- Triage โ ask the questions needed to understand scope (migration questions go here since answers shape the plan)
- Codebase Analysis + Plan File โ scan the project, produce
MIGRATION-PLAN.md, and pause for review
Step 0: Triage (BLOCKING โ requires AskUserQuestion)
Use the AskUserQuestion tool to gather the information below. Do not infer answers
from memory, prior conversations, or assumptions โ even if you think you know.
The migration path differs based on these answers; getting them wrong wastes the user's
time and produces incorrect guidance.
Do not proceed to Step 0.5 until the user has answered.
First AskUserQuestion call (up to 4 questions):
- Backend language / framework โ Present the most likely options based on any cues
in the conversation (e.g., Node.js, Go, Ruby, Python, Java). The user can always
pick "Other."
- Migration goal โ Full cut-over, incremental/phased migration, or just evaluating.
- Existing users and organizations โ Are they migrating an app with active users and
organizations in Stytch, staging/dev only, or starting fresh? This determines whether user
and organization migration planning is needed (user export, org-to-tenant mapping, SCIM
continuity, phased vs. big-bang cutover, forced re-login on cutover).
Second AskUserQuestion call โ Stytch feature usage (use multiSelect: true):
- Which Stytch features are in use? Present the highest-impact categories:
- Consumer Authentication โ which sign-in methods are enabled, such as OAuth/social login, email magic links, OTPs, passwords, passkeys, WebAuthn, mobile biometrics, MFA, TOTP, crypto wallet auth, or new-device notifications; whether the app uses Stytch UI, frontend SDKs, backend SDKs, or direct API calls.
- Multi-tenant / B2B Authentication โ whether the Stytch B2B model is used; how Organizations and Members are modeled; whether members can belong to multiple organizations; whether org discovery, org-specific login, or organization switching/session exchange is used.
- Organizations and Members โ organization metadata, member metadata, membership lifecycle, invitations, member search/update flows, deactivation behavior, and whether organization-specific auth policies are configured.
- Enterprise SSO โ whether SAML, OIDC, or both are used; which identity providers are connected; whether setup is handled internally or by customer admins; whether SSO is organization-specific, multi-organization, or standalone; whether role assignment or JIT provisioning depends on SSO claims.
- SCIM โ which workforce directories are connected; whether member provisioning, deprovisioning, group sync, group-to-role mapping, session revocation, or webhook handlers depend on SCIM behavior. Flag as high complexity.
- RBAC โ how Stytch resources, actions, permissions, and roles are defined; whether roles are consumer-level or organization/member-level; where permission checks happen in code; whether roles or permissions are included in session tokens; whether SSO or SCIM maps groups/claims to roles.
- JIT Provisioning โ which provisioning sources are allowed; whether users/members are automatically added to organizations after SSO, email-domain matching, discovery, invitations, or trusted token flows.
- MFA and Step-up Authentication โ which second factors are used, such as SMS OTP, email OTP, TOTP, passkeys, WebAuthn, or other factors; whether MFA is globally required, organization-specific, risk-based, or used only for sensitive actions.
- Sessions and Tokens โ how session tokens, session JWTs, intermediate sessions, custom claims, cookies, expiration, refresh, revocation, and frontend/backend session validation are implemented.
- Admin Portal UI โ which customer-admin workflows are handled by Stytch today, such as member management, organization settings, SSO setup, SCIM setup, or RBAC management; whether the application generates Admin Portal links or embeds Stytch-provided admin flows.
- Fraud & Risk / Device Fingerprinting (including Protected Auth) โ whether Device Fingerprinting is used for bot detection, credential stuffing protection, account takeover prevention, toll fraud prevention, free-trial abuse, remembered devices, trusted/unrecognized device detection, IP-geo restrictions, new-device notifications, or to enable Protected Auth mechanisms (which can block, challenge, add friction, or monitor suspicious attempts). Flag as high complexity if Stytch verdicts or Protected Auth flows influence authentication decisions or require custom enforcement logic.
- Connected Apps โ whether the application uses Stytch to act as an OAuth/OIDC authorization server; which first-party, third-party, public, or confidential clients exist; which authorization code, PKCE, consent, token, refresh token, revocation, custom scope, or RBAC-backed scope flows are implemented. Flag as high complexity. First-party โ Descope Federated Apps; third-party โ Descope Inbound Apps (public vs. confidential applies only to Inbound Apps).
- AI Agent / MCP Authentication โ whether Connected Apps are used for AI agents, MCP clients, CLI tools, external integrations, or agentic access to application data; review scopes, consent, dynamic client registration, token lifetimes, and organization-level controls before implementation. Flag for deeper review.
- Machine-to-Machine Authentication โ whether M2M clients, client credentials, client secrets, JWT access tokens, scopes, custom claims, or secret rotation are used for service-to-service authentication.
- Trusted Auth Tokens โ Stytch Trusted Auth Tokens let the application exchange an externally issued signed JWT for a Stytch
session. Stytch validates the JWT against a Trusted Auth Token Profile configured with issuer (
iss), audience (aud), public keys or JWKS URL, and claim mappings. Flag as high complexity.
- Webhooks, Event Logs, and Event Streaming โ which Stytch events are consumed by the application; whether event logs are shown to customers, streamed to external systems, used for compliance, or used to trigger internal user/org synchronization.
- The user can add others via โOther.โ
After both calls, summarize findings and flag high-complexity items before proceeding to Step 0.5. The main high-complexity Stytch areas are typically SCIM, Enterprise SSO with JIT provisioning, RBAC tied to SSO or SCIM, Fraud & Risk/Device Fingerprinting, Protected Auth, Connected Apps, AI Agent/MCP authentication, Machine-to-Machine authentication, and Trusted Auth Tokens.
Step 0.5: Engineer Review Checkpoint (BLOCKING โ requires AskUserQuestion)
These questions surface blockers the framework doesn't expose. Ask even the ones you think
you know. Use AskUserQuestion before proceeding to codebase analysis.
Batch into calls of up to 4 questions. Skip questions that are clearly inapplicable given
Step 0 answers (e.g., skip user migration planning if they said they're starting fresh).
Access and credentials
- Do they have access to the Descope Console and a Project ID? (If not, see Step 1.5.)
- Do they need a Management Key? Required for user CRUD, tenant management, RBAC, SSO/SCIM configuration, access keys, Inbound Apps, Outbound Apps, and other management operations.
- Do they have access to the Stytch Dashboard/API keys needed to inspect or export the current configuration, including Consumer Auth, B2B Organizations/Members, SSO, SCIM, RBAC, Connected Apps, Fraud & Risk, and Admin Portal settings?
Codebase scope
- Is this a Stytch Consumer Auth app, a Stytch Multi-tenant/B2B Auth app, or a hybrid app using both? This determines whether the migration centers on Users only or on Organizations/Members โ Tenants/Users.
- Are there places in the app that read claims or session fields directly from Stytch tokens or session responses, such as
user_id, member_id, organization_id, organization_slug, roles, permissions, trusted_metadata, untrusted_metadata, or custom claims? These need a Descope JWT Template or Flow Custom Claims configured before equivalent reads will work.
- Does the app read Stytch
organization_id, member_id, sso_connection_id, scim_group_id, Connected App client IDs, or RBAC role_id / resource_id / action values in many places? The Stytch Organization โ Descope Tenant remap ripples through SSO, SCIM, RBAC, JIT provisioning, Admin Portal replacement, Connected Apps, and membership checks โ confirm the organization model before writing code.
- Are there multiple services or microservices validating Stytch session tokens, session JWTs, access tokens, or Connected Apps tokens? Each service needs to be updated to validate the correct Descope-issued JWTs or OAuth/OIDC tokens.
- Does the application use Stytch frontend SDK helpers, backend API calls, direct REST calls, Stytch UI components, or all of the above? This determines whether the migration is mostly Flow/UI replacement, backend SDK replacement, or both.
- Does the app depend on Stytch webhooks to keep its own database in sync? Search for webhook handlers before changing user, organization, member, SCIM, RBAC, fraud, or Connected Apps behavior.
Deployment and risk
- Do they have multiple environments (dev / staging / prod)? Each needs its own Descope project and Project ID, with matching redirect URLs, auth domains, SSO/SCIM configuration, Connected Apps, and environment-specific secrets.
- Is there a maintenance window, or does this need to be zero-downtime?
- Are any external customers, enterprise IdPs, SCIM directories, OAuth clients, MCP clients, or machine-to-machine clients already integrated with the Stytch production project? If yes, plan customer-facing cutover steps, not just code changes.
- Are login URLs, callback URLs, custom auth domains, email domains, OAuth issuer URLs, or JWKS URLs contractually or technically expected to stay stable? If yes, flag early because they affect SSO, sessions, Connected Apps, and token validation.
User, organization, and member migration (if they indicated existing users/orgs in Step 0)
- How many users, Organizations, and Members exist? This determines export approach and whether a phased cutover is warranted.
- Are they using Stytch Consumer Auth users, Stytch B2B Members, or both? Consumer users and B2B Members have different object shapes and should not be collapsed without confirming the target model.
- Do Stytch Members belong to multiple Organizations? If yes, preserve tenant membership and role assignment per organization when mapping to Descope Tenants.
- Do they use passwords in Stytch? Plan how password credentials carry over: import if supported, force reset, staged password migration, or replacement with passwordless methods. Verify the current Stytch export capability and Descope import path before committing to an approach.
- Which Stytch authentication methods are in use: OAuth/social login, OTP, magic links, passwords, passkeys/WebAuthn, mobile biometrics, TOTP, MFA, crypto wallets, or custom auth factors? Confirm migration feasibility for each method before writing implementation instructions.
- Big-bang cutover or phased? Map each Stytch Organization to a Descope Tenant first; user/member migration, tenant membership, SSO, SCIM, JIT provisioning, and tenant-scoped roles depend on it.
- SCIM is a lifecycle system, not a one-time import. If Stytch SCIM is enabled, enterprise directories will keep pushing create/update/deactivate/group events after cutover. A single user import is not enough โ every SCIM workflow must be re-pointed at Descope before cutover, or provisioning silently breaks.
- Are they aware that active Stytch sessions will be invalidated on cutover unless a session-bridging approach is used? Plan for forced re-login, phased rollout, or a temporary compatibility layer.
- Does the app store Stytch IDs in its own database? If yes, plan an ID mapping table for Stytch
user_id, member_id, organization_id, role_id, Connected App client IDs, and any other persisted identifiers.
Gaps to flag immediately (don't ask โ flag these proactively based on Step 0 answers)
- If they're using Fraud & Risk / Device Fingerprinting: flag for security-flow review. Stytch verdicts, device IDs, trusted device logic, IP-geo restrictions, new-device notifications, and abuse-prevention decisions may need to be recreated with Descope Fingerprinting, Flow conditions, connectors, audit events, or app-side policy.
- If they're using Protected Auth: flag that this is not a direct SDK toggle migration. Protected Auth behavior should be redesigned as Descope Flow-based risk handling: allow, challenge, block, or notify based on risk signals and policy.
- If they're using Connected Apps: flag for deeper OAuth/OIDC review before implementation. Inventory clients, redirect URIs, public vs. confidential clients, PKCE, scopes, consent records, access token lifetimes, refresh token behavior, issuer/JWKS dependencies, and resource-server validation. First-party Stytch clients map to Descope Federated Apps; third-party clients map to Descope Inbound Apps (public vs. confidential applies only to Inbound Apps).
- If they're using AI agent / MCP authentication through Stytch Connected Apps: flag for dedicated review. This may map to Descope Inbound Apps, Agentic Identity Hub, MCP server authorization, DCR/CIMD, resource scopes, or tenant-aware policies.
- If they're using Machine-to-Machine authentication: identify all M2M clients, secrets, scopes, token audiences, and rotation requirements. Default to Resources + Inbound Apps + Policies; use Access Keys only for simple internal JWT exchange without OAuth scope/
aud enforcement.
- If they're using Trusted Auth Tokens or external JWT exchange: flag as high complexity. Confirm issuers, JWKS URLs, audiences, subject mapping, claim mapping, JIT behavior, and whether the exchange creates a user session or only API access. In Descope, this maps most closely to Inbound Apps with the JWT Bearer grant
- If they're using SCIM: set up Descope SCIM and customer IdP cutover before production migration. Missing this can break provisioning/deprovisioning even though interactive login may still appear to work.
- If they're using webhooks or event logs: identify business-critical handlers and configure Descope webhooks, audit connectors, or event streaming before cutover to avoid gaps in compliance, sync, or customer-visible activity.
Console/Flow/Widget opportunities (flag before codebase analysis, then ask):
- If the app uses the Stytch Admin Portal UI or Stytch Admin Portal components for member management, organization settings, SSO setup, or SCIM setup: ask whether Descope SSO Setup Suite and Admin Widgets can replace that workflow instead of rebuilding it as custom code. Do not default to building custom admin setup screens.
- If the app has a profile edit page, member management page, organization settings page, or tenant-admin UI: ask whether a Descope Widget covers the use case.
- If the app has a separate MFA enrollment page: ask whether MFA should be integrated into the main sign-in Flow as a step or subflow instead.
- If any server-side code initiates SSO, generates emails, runs custom checks, calls fraud APIs, or makes decisions during the auth journey: ask whether that logic can become a Descope Flow step, condition, or Connector instead of server code.
- If the app uses custom Stytch UI built with frontend SDKs: ask whether Descope Flows can replace the custom UI or whether the customer requires a headless SDK migration.
- If the app uses Stytch Connected Apps and hosts its own OAuth authorization endpoint UI: ask whether Descope Inbound Apps can own more of the OAuth/OIDC authorization-server behavior, consent, token issuance, and client configuration.
- If the app has risk-based auth, remembered-device behavior, new-device notifications, or custom fraud challenges: ask whether these should be modeled as Flow branches using Descope risk signals and messaging/connectors.
Summarize any blockers and Console/Flow/Widget opportunities before proceeding to codebase analysis.
Step 1: Codebase Analysis
Scan the codebase to map every auth touchpoint before writing the plan.
Stytch ships backend SDKs (Python, Go, Node, Ruby, Java/Kotlin/JVM), frontend SDKs
(React, Next.js, Vanilla JS), and mobile SDKs (React Native, iOS Swift, Android Consumer SDK โ
a headless Kotlin Multiplatform library targeting Android). Adapt the file extensions below to
whichever surfaces appear in the project.
Run these searches (adapt file extensions to the user's language and platform):
grep -rni "stytch\|@stytch\|stytchauth\|com\.stytch" \
--include="*.ts" --include="*.tsx" --include="*.js" --include="*.jsx" \
--include="*.mjs" --include="*.cjs" --include="*.py" --include="*.go" \
--include="*.rb" --include="*.java" --include="*.kt" --include="*.kts" \
--include="*.swift" --include="*.gradle" --include="*.gradle.kts" \
--include="Podfile" --include="Gemfile" \
--exclude-dir=node_modules --exclude-dir=.next --exclude-dir=dist --exclude-dir=venv \
--exclude-dir=build --exclude-dir=.gradle \
. 2>/dev/null
grep -rn "STYTCH_\|stytch\." \
--include="*.ts" --include="*.tsx" --include="*.js" --include="*.jsx" \
--include="*.py" --include="*.go" --include="*.rb" --include="*.java" --include="*.kt" \
--include="*.swift" --include="*.env*" --include="*.yml" --include="*.yaml" \
--include="Dockerfile" \
--exclude-dir=node_modules --exclude-dir=.next --exclude-dir=build \
. 2>/dev/null
grep -rni "\.sessions\|\.b2b\|\.b2c_client\|\.otps\|\.magicLinks\|\.magic_links\|\.passwords\|\.oauth\|\.webauthn\|\.totps\|\.mfa\|\.m2m\|\.scim\|\.connected\|\.idp\|\.rbac\|\.discovery\|\.impersonation\|\.users\|\.organizations\|session_token\|session_jwt\|intermediate_session_token\|organization_id\|organization_slug\|member_id\|trusted_auth\|external_token\|custom_claims\|authenticateJwt\|authenticate(" \
--include="*.ts" --include="*.tsx" --include="*.js" --include="*.jsx" \
--include="*.py" --include="*.go" --include="*.rb" --include="*.java" --include="*.kt" \
--include="*.swift" \
--exclude-dir=node_modules --exclude-dir=.next --exclude-dir=build \
. 2>/dev/null
grep -rn "StytchProvider\|StytchB2BProvider\|Products\|StytchB2B\|StytchLogin\|StytchHeadlessClient\|useStytch\|useStytchUser\|useStytchSession\|createStytchUIClient\|StytchConsumerSDK\|StytchClient\|StytchUI\|@stytch/nextjs\|@stytch/react\|@stytch/vanilla-js\|@stytch/react-native" \
--include="*.ts" --include="*.tsx" --include="*.js" --include="*.jsx" \
--include="*.swift" --include="*.kt" \
--exclude-dir=node_modules --exclude-dir=.next --exclude-dir=build \
. 2>/dev/null
grep -rn "scim\|saml\|sso\|adminPortal\|admin_portal\|discovery\|jit_provision\|connectedApp\|connected_app\|m2m\|client_credentials\|deviceFingerprint\|device_fingerprint\|protectedAuth\|protected_auth\|dfp\|webhook" \
--include="*.ts" --include="*.tsx" --include="*.js" --include="*.jsx" \
--include="*.py" --include="*.go" --include="*.rb" --include="*.java" --include="*.kt" \
--include="*.swift" \
--exclude-dir=node_modules --exclude-dir=.next --exclude-dir=build \
. 2>/dev/null
find . -maxdepth 4 \( \
-name "package.json" -o -name "go.mod" -o -name "requirements.txt" -o \
-name "Gemfile" -o -name "pom.xml" -o -name "build.gradle" -o -name "build.gradle.kts" -o \
-name "Podfile" -o -name "Podfile.lock" \
\) ! -path "*/node_modules/*" ! -path "*/build/*" \
-exec grep -l "stytch\|@stytch\|stytchauth\|com\.stytch" {} \;
For each hit, record:
- File path and line โ where the change happens
- What it does โ import, route protection, claim access, org/tenant read, SSO/SCIM config, webhook handler, logout handler, etc.
- Complexity โ Low (drop-in replacement), Medium (logic rewrite), High (no equivalent)
Read package.json (or equivalent) for the exact framework version โ this affects async
behavior (Next.js 15 vs 14) and SDK compatibility.
If the Descope Docs MCP is available, use search-descope-docs or ask-question-about-descope
to verify current SDK method names for anything you plan to reference in the plan.
Step 2: Write MIGRATION-PLAN.md
Write MIGRATION-PLAN.md to the working directory using the triage answers and codebase
analysis.
Two audiences: the engineer needs enough technical detail to execute; the PM or tech lead
needs scope, risk, and timeline without decoding jargon. Use plain English. Explain
technical terms on first use. Open each section with a sentence summarizing what it means
before presenting tables or evidence. Say what breaks if a risk is missed, not just that it
exists. Pair complexity labels with time estimates; skew toward the lower bound โ SDK swaps and mechanical rewrites are usually faster than they look, and repetitive files in a group after the first go much faster. Group execution into phases so parallel vs. sequential work is clear.
The plan must include these sections, in this order:
Overview
2โ3 sentences: what's being replaced, what replaces it, and the recommended approach with a
one-sentence rationale. Add one sentence on what doesn't change โ user-facing login behavior,
sessions, organizations, and existing accounts are preserved.
Include a Migration at a Glance table:
| |
|---|
| Approach | Full native migration |
| Files changing | N source files across N areas |
| Console setup | N configuration steps before launch |
| User impact | No re-login required / Users will need to log in once after cutover |
| Estimated engineering effort | NโN hours |
| Biggest risk | One sentence naming the highest-complexity item |
What's Changing and Why
Prose (not a table) describing what each part of the system does today and what it does
after. Example:
Today, Stytch handles everything related to login: Stytch UI or frontend/mobile SDKs render
the login experience, issue session_token / session_jwt, and the backend SDK validates
sessions on every request โ routing B2B users to the right organization SSO connection when
applicable. After this migration, Descope takes over all of those responsibilities. The login
UI becomes a Descope Flow embedded in the app. Session validation moves to the Descope SDK.
Stytch Organizations become Descope Tenants. STYTCH_PROJECT_ID, STYTCH_SECRET, and the
public token are replaced by DESCOPE_PROJECT_ID (and NEXT_PUBLIC_DESCOPE_PROJECT_ID for
the browser).
Stytch features in use that need to carry over: [list in plain English, one clause each].
Tailor to triage findings.
Client SDK vs. Backend SDK: A Specific 1-to-1 Mapping
For every Stytch touchpoint found in triage, produce a concrete, one-to-one mapping โ Stytch construct โ the exact Descope SDK and method that replaces it โ
and state explicitly whether that replacement runs in the client SDK or the backend SDK, and
why. Use this division of responsibility:
- Client SDK (
@descope/web-js-sdk, @descope/react-sdk, @descope/nextjs-sdk client
components, or the <descope-wc> web component) โ everything the user's browser or mobile app
does: rendering the login/sign-up UI (a Descope Flow replaces Stytch UI, @stytch/react,
@stytch/nextjs, @stytch/vanilla-js, or mobile SDK login flows), initiating authentication,
holding the session on the client, refreshing the token, and reading the current user for UI
purposes. This replaces Stytch frontend/mobile providers (StytchProvider, useStytch,
useStytchUser, useStytchSession), headless client calls, and any client-side session access.
It uses only the public Project ID โ never a Management Key.
- Backend SDK (
@descope/node-sdk, descope (Python), github.com/descope/go-sdk, etc.) โ
everything the server does: validating the session JWT on every request (replacing Stytch
server-side sessions.authenticate() / sessions.authenticateJwt() and route middleware),
checking roles and permissions, and โ with a Management Key โ all administrative operations done by
ID (user and tenant CRUD, role/permission definitions, SSO/SCIM configuration, ReBAC). This
replaces Stytch backend SDK calls (stytch.sessions, stytch.b2b.*, stytch.m2m, etc.) and
every Stytch Management API call.
For each file or area, name the Stytch call, the Descope SDK that replaces it, which side it runs on,
and the reason (e.g. "session validation must stay server-side because the validation/Management key
cannot ship to the browser"). When one Stytch feature spans both sides โ for example a Stytch UI or
mobile login flow (now a client Flow) plus per-request sessions.authenticateJwt() validation (now
the backend SDK) โ split it into its client half and its backend half so the reader sees exactly what
moves where, and why each piece belongs on that side.
Auth Touchpoints: What the Code Analysis Found
Open with the scope count (e.g., "11 files across 4 areas"). Group by area, not file path.
Each group gets a sentence on what it does and what changes.
Session handling (3 files) โ These files read and validate the current user's login
state. They'll be updated to use the Descope session SDK instead of Stytch session
authentication (sessions.authenticateJwt(), sessions.authenticate(), or frontend
useStytchSession()).
| File | What it does today | What changes |
|---|
lib/auth.ts:34 | Validates session_jwt via stytch.sessions.authenticateJwt(); returns user_id, organization_id, roles | Rewritten to return Descope authInfo; a thin adapter layer preserves the shape callers expect |
middleware.ts:12 | Reads stytch_session cookie and blocks unauthenticated requests app-wide | Updated to validate Descope DS/DSR cookies via Descope session validation; logic is identical, SDK call changes |
Login / auth UI (2 files) โ These render Stytch UI or run headless Stytch client
flows (magic links, OTP, OAuth, passkeys, B2B discovery). Descope replaces this with an
embedded Flow component (or hosted Flow); token exchange and callback routes change shape.
| File | What it does today | What changes |
|---|
app/login/page.tsx | Renders <StytchLogin> or useStytch() headless flow | Replaced with <Descope flowId="..."> (or hosted Flow); onSuccess wires the Descope session client-side |
app/api/authenticate/route.ts | Exchanges token / session_token from Stytch callback | Deleted or rewritten โ most flows complete client-side in Descope; verify any server-side exchange against the framework section |
Cover all functional groupings (B2B org/member management, SCIM webhooks, M2M token issuance,
Connected Apps, mobile SDK auth, etc., when present). End with: "Total: N files. Estimated
code-change effort: NโN hours."
Feature Migration: Stytch โ Descope
For each Stytch feature confirmed in triage, write a short paragraph: what it's trying to
accomplish, the best Descope approach for that goal, what's different, and what action is
required. The best approach may be a Flow, Widget, SSO Setup Suite, or Console configuration
rather than a direct SDK equivalent โ reason about the intent, not just the API surface. Only
recommend SDK code when programmatic control is genuinely required. Example:
Multi-tenancy (Stytch Organizations โ Descope Tenants)
Stytch multi-tenant auth is built around Organizations and Members. A Stytch
Organization represents a tenant/customer in the application, and a Member is a user's account
within that Organization. Organization-scoped configuration can include SSO connections, SCIM,
JIT provisioning, approved auth methods, MFA policies, RBAC behavior, custom metadata, and
Connected Apps settings. Descope has the same core concept, called Tenants. In most migrations,
map one Stytch organization_id to one Descope tenant ID.
Most code that handles Stytch Organizations is management/admin code that passes a Stytch
organization_id to B2B APIs โ for example, loading an organization, updating organization
settings, managing members, assigning roles, configuring SSO, or configuring SCIM. That becomes
Descope tenant/user management code that passes a Descope tenant ID to the relevant tenant,
user, SSO, SCIM, or RBAC operation. This is mostly by-ID management work, not token parsing.
The main request-time difference is the session shape. In Stytch B2B, the authenticated session is
tied to a specific Organization and returns fields such as member_session.organization_id,
member_session.organization_slug, member_session.roles, the member object, and the
organization object. In Descope, tenant membership and tenant-scoped roles/permissions are read
from the validated session/JWT and should ideally be checked with SDK helpers such as
validateTenantRoles(...) or validateTenantPermissions(...) rather than by manually parsing
claims.
Confirm the OrganizationโTenant mapping first, since it ripples into SSO, SCIM, JIT provisioning,
RBAC, Admin Portal replacement, Connected Apps, and any application database tables that store
organization_id. Also confirm whether Stytch Members can belong to multiple Organizations and
whether the app supports organization switching, because that determines whether the Descope
migration needs tenant selection, active-tenant handling, or separate tenant-scoped login routes.
Effort: Medium (1โ2 hours of code changes). Confirm the data migration path for orgs first.
Only include confirmed features.
Before the Code Can Run: Required Configuration
Some Descope behavior is configured in the console, not in code. List every item that must
be set up before the app works, as checkboxes with a plain description of what it is, why
it's needed, and roughly how long it takes. Group into "Required before any testing" and
"Required before production":
Required before any testing:
- Create a Descope project โ Takes 2 minutes. Produces a Project ID that replaces
the STYTCH_PROJECT_ID in the app's environment variables.
- Create an authentication flow โ Descope uses a visual "flow" to define the login
experience (what methods are offered, in what order). The built-in
sign-up-or-in flow
works for most apps and requires no customization to start.
- Configure a user profile token template โ By default, Descope session tokens don't
include the user's name, email, or profile photo. This template needs to be configured so
the app can display user profile information. Without it, any part of the UI that shows the
user's name or email will show nothing after login. (~10 minutes)
Required before production:
- Create tenants for each Stytch Organization โ Descope Tenants must exist before
tenant-scoped code (SSO, roles, membership) will work.
- Create roles (or whatever the codebase references) โ Descope roles must exist in the
console before code that assigns them will work.
- Configure SSO connections per tenant (or enable the SSO Setup Suite for self-serve) โ SAML/OIDC connections need to be recreated.
- Configure social login providers (Google, GitHub, etc.) โ OAuth credentials for
each provider need to be entered in the console. (~15 minutes per provider)
- (continue for each item found in analysis)
Environment Variables
Diff table with plain-English notes for each removal and addition:
| Remove | Add | Why |
|---|
STYTCH_PROJECT_ID | DESCOPE_PROJECT_ID | Your unique Stytch project ID. Descope uses a Project ID for the same purpose. |
STYTCH_SECRET | DESCOPE_MANAGEMENT_KEY | Backend secret used to securely authenticate Stytch API requests. Descope session validation uses only the Project ID; a Management Key is needed only for server-side user/tenant/SSO/SCIM administration. |
NEXT_PUBLIC_STYTCH_PUBLIC_TOKEN | NEXT_PUBLIC_DESCOPE_PROJECT_ID | Stytch's frontend-facing token for initializing client SDKs. Descope uses the same value as DESCOPE_PROJECT_ID, exposed to the browser for the login Flow component (Next.js and other frontend frameworks). |
Connected Apps client_id (e.g. STYTCH_CONNECTED_APP_CLIENT_ID or similar) | DESCOPE_INBOUND_APP_CLIENT_ID | Only if the app uses Stytch Connected Apps as an OAuth/OIDC client โ replace with the Descope Inbound App client ID (Console โ Inbound Apps). First-party Connected Apps clients map to Federated Apps instead and do not use this variable. For confidential Inbound Apps, also add DESCOPE_INBOUND_APP_CLIENT_SECRET. |
Follow with: "Net change: 2-3 variables removed, 1โ4 added (Connected Apps env vars only if applicable). No secrets need to be rotated
on the Stytch side โ those credentials stop being used."
User & Organization Migration (only if existing users/orgs need to be migrated)
Prose strategy first, then steps. Start with: "X existing users across Y organizations need to be in Descope before cutover." Describe:
- The plan: whether this is big-bang (all users/orgs moved before cutover) or phased, and why
- Orgโtenant mapping: each Stytch Organization becomes a Descope Tenant;
- What users will experience: will they need to log in again? Will anything look different?
- The biggest dependency: how password credentials carry over, and whether SCIM directories must be re-pointed at Descope (a continuing pipeline, not a one-time import)
End with a brief checklist of the migration steps at the level a PM can track:
- Export users and organizations from Stytch
- Map each Stytch Organization to a Descope Tenant
- Re-point SCIM\ at Descope (if Stytch SCIM is in use)
- Do a dry run of the import against the Descope dev project
- Review dry-run output for errors
- Run live migration against staging, then production
Trade-offs and considerations
Things that could affect timeline, user experience, or scope. Write each in plain English
with three parts: what it is, what breaks if it's ignored, and what to do.
Format each as a named callout:
Consideration: Organization-to-tenant mapping affects almost every B2B feature
Stytch Organizations should usually map to Descope Tenants. If this mapping is wrong, SSO, SCIM,
roles, permissions, domain routing, and user membership checks may all break.
Action: Confirm the organization model before writing migration code.
Consideration: SCIM is a lifecycle system, not just a user import
Stytch's SCIM may create, update, suspend, and delete users or group memberships continuously.
A one-time import is not enough if enterprise directories keep syncing after cutover.
Action: Identify every SCIM workflow and re-point it at Descope before cutover.
Consideration: Admin Portal UI should not automatically become custom code
If the app uses the Stytch Admin Portal UI, the Descope equivalent may be the SSO Setup Suite or a
Widget rather than a custom settings page.
Action: Ask whether tenant admins currently self-configure SSO/SCIM/domain verification.
Consideration: User profile data won't appear after login until a token template is configured
Descope session tokens don't include name, email, or profile photo by default. Any UI that
displays user information will show blank values after migration until the token template is set
up in the Descope console. This is a one-time configuration step, not a code change.
Action: Configure the token template before running any tests. Estimated time: 10 minutes.
Include only applicable trade-offs and considerations.
Execution Plan
Open with one sentence: phases run in sequence; steps within a phase can run in parallel.
Then labeled phases, each with a time estimate:
Phase 1 โ Console Setup (~30โ60 minutes, no code required)
Can be done by any team member with Descope console access, in parallel with other work.
- Create Descope project, copy Project ID
- Configure Approved Domains (domain only โ e.g.
localhost:3000, not http://localhost:3000/authenticate)
- Create authentication flow (use the built-in
sign-up-or-in to start)
- Configure user profile token template
- Create tenants for each Stytch Organization (list actual orgs found)
- Create roles: (list actual roles found)
- Configure SSO connections per tenant or enable the SSO Setup Suite (if SSO in use)
- Configure social login providers: (list actual providers found)
Phase 2 โ Code Changes (~XโY hours, 1 engineer)
Work through files in the order listed. Run a compile check after each group.
- Update environment variables in
.env.example and CI config (15 min)
- Rewrite session helper /
withAuth() usage (30 min)
- Swap AuthKit provider/middleware for Descope equivalents (15 min)
- Update protected route files to use new session check (45 min)
- Repoint org handling to tenant IDs โ management calls pass a
tenantId; request-time session reads use tenants/dct (varies)
- Update logout โ two-step logout (15 min)
- Compile check and fix any type errors before proceeding
Phase 3 โ User & Organization Migration (~1โ2 hours, includes dry run)
Run against dev/staging first. Do not run against production until Phase 4 passes.
- (steps from user & organization migration section above)
Phase 4 โ Testing (~30โ45 minutes)
- Compile passes with zero errors
- Server starts, no crashes on startup
- Unauthenticated routes redirect to login correctly
- Login flow completes, user profile data appears (confirms token template is working)
- Tenant/SSO routing works for at least one organization
- Logout invalidates session
Phase 5 โ Production Cutover
- (cutover-specific steps based on their strategy โ maintenance window, phased rollout, SCIM re-point, etc.)
Total estimated engineering effort: NโN hours across N engineers.
Blocking dependencies: (list anything on the critical path โ console access, SCIM re-point, etc.)
After writing MIGRATION-PLAN.md, stop and tell the user:
MIGRATION-PLAN.md has been written to your working directory. It maps every auth
touchpoint found, lists what needs Console setup before the first test, and calls out
trade-offs and considerations that could affect the timeline.
Take a look before we start making changes. When you're ready to proceed, say so.
Do not proceed to Part 3 unless the user confirms.
Part 3: Execution
Execute the plan in MIGRATION-PLAN.md Execution Plan order. Follow the detailed guidance below
for each step.
Context Continuity Protocol
Context can be lost between turns. These rules keep the migration coherent.
Step 3.0 โ Create MIGRATION-STATE.md before touching any code.
Write MIGRATION-STATE.md to the working directory from the template below. It's the
source of truth for migration state โ keep it current throughout execution.
# Migration State
_Last updated: [timestamp of last completed step]_
## Project Context
- Framework: [e.g., Next.js 14, Express + React]
- Language: [TypeScript / Python / Go]
- Package manager: [npm / yarn / pnpm / pip / etc.]
- Migration goal: [Full cutover / Phased / Evaluating]
## Triage Answers
- Existing users: [Yes โ N users / No โ greenfield]
- Existing organizations: [Yes โ N orgs โ tenants / No]
- Password migration needed: [Yes / No]
- Stytch features in use: [comma-separated list]
- Multiple environments: [Yes: dev/staging/prod / No]
- Zero-downtime required: [Yes / No]
## Files Inventory
_All files that need to change. Update status after each step._
| File | Change | Status |
|---|---|---|
| `app/callback/route.ts` | Delete/rewrite | โฌ Pending |
| `lib/auth.ts` | Rewrite session helper | โฌ Pending |
| `middleware.ts` | Update session check | โฌ Pending |
## Console Setup Checklist
- [ ] Descope project created โ Project ID: (fill in when done)
- [ ] Approved Domains configured (domain only โ e.g. `localhost:3000`, not `http://localhost:3000/authenticate`)
- [ ] JWT template configured
- [ ] Tenants created for each Stytch Organization: (list)
- [ ] Roles created: (list roles)
- [ ] SSO connections / SSO Setup Suite configured: (list)
- [ ] Social providers configured: (list providers)
## Decisions Log
_Non-obvious decisions made during migration โ preserves rationale if context is lost._
_(none yet)_
## Current Phase
Phase 1 โ Console Setup (not started)
## Next Action
Complete console setup per MIGRATION-PLAN.md before making any code changes.
## Blockers
_(none)_
Rule 1 โ Re-read before every turn.
At the start of every execution turn, re-read MIGRATION-PLAN.md and MIGRATION-STATE.md
before writing any code or making any decision.
Rule 2 โ Verify context before every code change.
If the framework, migration path, triage answers, or next step aren't clear from the
conversation, re-read both files before proceeding. Then output a context line:
Migration context: Next.js 14 ยท Phase 2, step 3/8 ยท Next: rewrite lib/auth.ts
If this line can't be filled in accurately, re-read the files first.
Rule 3 โ Update MIGRATION-STATE.md immediately after each step.
Mark the file done in the Files Inventory, update "Current Phase" and "Next Action", and
append any non-obvious decision to the Decisions Log. Do this before the next step.
Pre-Generation Protocol (apply before writing any code)
Run before generating any import, wrapper type, or helper. Skipping produces code that
compiles but fails at runtime.
1. Verify SDK exports before writing any import.
When the Docs MCP is available, use ask-question-about-descope to confirm the exact method name, option shape, and return type before writing any SDK call. This is faster and more reliable than reading type declarations. Do not write a method name and add a hedge like "verify the exact name" โ just verify it.
When the Descope MCP server is unavailable: resolve the package's type declarations (node_modules/<pkg>/dist/types/ or its package.json types field) and confirm the exact exported name and signature. For Go, run go doc. For Python, check the SDK stubs.
Prefer local node_modules/ over GitHub when reading type declarations. Installed packages reflect the exact version in use. If the Descope package isn't installed yet, install it first, then read local type declarations. Only fall back to GitHub if the package can't be installed in the current environment.
This applies to every SDK call you write, not just the first import. Field names on
option objects, hook return shapes (useDescope() returns the SDK directly, not { sdk }),
and subpath exports (/client vs root) differ just as often.
1a. After rewriting any module, grep for remaining imports of the removed package.
grep -r "from '@stytch/\|from 'stytch'\|from \"stytch\"" --include="*.ts" --include="*.tsx" --include="*.js" --include="*.jsx" .
Add remaining hits to the work list.
2. Derive wrapper types from the actual return type.
Read the function's declared return type and build the wrapper to match. Stytch's field
names, nesting, and flags differ โ don't infer from them.
3. Check dependency versions before generating framework-specific code.
For Next.js: cookies() and headers() from next/headers are synchronous in v14 and
async in v15. Read package.json (or go.mod, requirements.txt) first.
4. When making a helper async, propagate to all callers immediately.
In TypeScript, async on a shared utility silently breaks callers that omit await. Grep
for all call sites of the changed function and update them in the same pass. The cascade can
span 10โ20 files.
5. Verify published package versions before writing to package.json or running npm install.
Don't reuse Stytch's version number or rely on training data for versions. Before writing any
install command:
npm view @descope/node-sdk version
npm view @descope/nextjs-sdk version
If npm is unavailable, leave the version as "latest" and flag it.
Step 1.5: Descope Project Setup & Console Configuration
Several steps require Descope Console setup that can't be done in code. The app compiles
without them but won't work at runtime.
Use AskUserQuestion to ask whether they already have a Project ID and working Flow. If
yes, skip to verifying items 5โ8 โ these are easy to miss even for existing projects.
1. Create a project and get your Project ID
- Sign in at console.descope.com
- Your Project ID appears in the top-left project selector and under Project โ General. It starts with
P (e.g. P2abc123...).
- For Next.js client-side code, this becomes
NEXT_PUBLIC_DESCOPE_PROJECT_ID. For all server-side SDKs, it's DESCOPE_PROJECT_ID.
2. Get a Management Key (if needed)
Required for: user management API, role/permission management, tenant operations, SSO/SCIM
configuration, ReBAC (FGA), Outbound Apps. If the app does any server-side user, tenant, SSO,
or SCIM management, they need this.
- Console โ Company โ Management Keys โ + Management Key
- Store as
DESCOPE_MANAGEMENT_KEY. Treat like a secret โ never expose client-side.
3. Choose or create a Flow
A Flow is the auth UI sequence. Reference it by Flow ID in the web component.
- Console โ Flows
- The built-in "sign-up-or-in" flow handles email/password, OTP, and social login.
Use it for most migrations.
- To customise: duplicate "sign-up-or-in", rename it, then edit in the visual builder.
- The Flow ID is in the URL when editing and in the flow list.
- There are 100+ Flow templates in the library โ check for an existing template before building a custom flow. See
references/flows-and-widgets.md โ Flows.
- MFA: add an MFA step to the Flow or embed MFA as a subflow. Descope manages MFA enrollment through Flows. For factor-deletion SDK support by type, see
references/implementation-nuances.md โ MFA section.
4. Configure authentication methods
- Console โ Authentication โ select methods (Email OTP, Magic Link, Social, SSO, Passkeys, etc.)
- For social providers (Google, GitHub, etc.): configure OAuth credentials here, then add
the provider step to your Flow.
- For enterprise SSO (SAML/OIDC): To configure SSO for a specific tenant or to enable the SSO Setup Suite for tenant-admin self-serve, go to Console โ Tenants, select the desired tenant, and click Tenant Settings. For correct SSO callback and ACS URLs (social OAuth, SAML ACS, what NOT to use), see
references/implementation-nuances.md โ Social login / SSO section.
5. Configure Approved Domains (local dev and production)
Console โ Project Settings โ Security โ Approved Domains.
Descope validates redirect URLs against this domain list โ not full redirect URIs like Stytch.
Enter domain only: no http:///https://, no path.
- Local dev:
localhost:3000 (include port)
- Production:
myapp.com or app.myapp.com
Do not carry over Stytch callback URLs like http://localhost:3000/authenticate. Descope
embedded Flows complete auth client-side; there is no /authenticate route to whitelist. See
references/implementation-nuances.md โ Approved Domains gotcha.
6. Configure a JWT Template (almost always needed)
Stytch tokens may include profile fields; Descope tokens do not by default.
- Console โ Project โ JWT Templates
- Add claims:
{"email": "{{user.email}}", "name": "{{user.name}}", "picture": "{{user.picture}}"}
- Apply the template to your project. Without this step, any code reading
token.email
will get undefined after migration.
7. Create roles in the Console (if using RBAC)
Descope roles are referenced by name, not by ID. They must be created manually in the
Console before the code that assigns them will work.
- Console โ Authorization โ RBAC โ + Role
- Create each role the app references (e.g.
admin, member)
8. Define custom attributes (if using Stytch metadata)
Stytch metadata maps to Descope customAttributes, but the models are slightly different. Stytch
stores arbitrary JSON in metadata fields, while Descope custom attributes should be pre-defined in the
Console schema before setting them via the SDK.
Tenant custom attributes: map Stytch Organization trusted_metadata to Descope tenant
customAttributes. Configure these in Console โ Tenants โ Custom Attributes tab โ Create
Attribute.
User custom attributes: map Stytch Consumer User trusted_metadata and safe B2B Member
trusted_metadata to Descope user custom attributes. Configure these in Console โ Project โ
Custom Attributes.
9. Env var summary
| Variable | Where to get it | Used by |
|---|
DESCOPE_PROJECT_ID | Console โ Project Settings | All server-side SDKs |
NEXT_PUBLIC_DESCOPE_PROJECT_ID | Same value as above | Next.js AuthProvider (client-side) |
DESCOPE_MANAGEMENT_KEY | Console โ Company โ Management Keys | Management SDK, SSO/SCIM, Outbound Apps API |
10. Consider Widgets for management UI
Before migrating custom profile pages, user management pages, role assignment UI, or admin
SSO/SCIM setup pages, ask whether a Descope Widget or the SSO Setup Suite covers the use case.
See references/flows-and-widgets.md โ Widgets.
After completing console setup: Update MIGRATION-STATE.md โ check off each completed
item in the Console Setup Checklist, record the Project ID in the file, and set Next Action
to the first code change step.
Step 2: Framework-Specific Migration
Stytch publishes three SDK families:
- Backend SDKs (one per language):
stytch-node (stytch), stytch-python (stytch), stytch-go, stytch-ruby, stytch-java (Java/Kotlin/JVM). These call the Stytch API and authenticate sessions server-side.
- Frontend SDKs (per JS framework):
@stytch/react, @stytch/nextjs, @stytch/vanilla-js. These render the login UI (Stytch UI or headless) and hold the client session.
- Mobile SDKs:
@stytch/react-native, the iOS Swift SDK, and the Android Consumer SDK (a headless Kotlin Multiplatform library targeting Android).
The recipes below map each Stytch SDK to its Descope target โ one section each. A Stytch app on a server framework not listed (Express, Flask, FastAPI, Rails, Spring) is using the underlying language Backend SDK (stytch-node, stytch-python, etc.), so map it via that SDK's section.
The framework recipes below are stubs listing the Stytch idioms that need mapping. Confirm the exact Stytch SDK surface for the user's stack and the matching Descope SDK calls via the Descope MCP or local type declarations before generating any code. Do not ship code from these stubs without verification.
Read references/implementation-nuances.md in two passes before writing any code:
- General Insights (always) โ covers architecture, feature mapping, and common gotchas that apply to every migration regardless of framework.
- Framework section (use the file's ToC and
offset to jump directly) โ read only the section matching the user's stack.
When a new framework is added to the file, add it to this list.
Common Stytch idioms to map (all frameworks)
Frontend Stytch SDKs expose UI components and client session hooks; backend SDKs authenticate the
session server-side. The mappings below apply across stacks:
- Stytch UI (
<StytchLogin> / <StytchB2B>) or headless useStytch() login โ embedded Descope Flow (<Descope flowId> / <descope-wc>) or hosted Flow, wiring onSuccess
useStytchSession() / useStytchUser() (client session access) โ Descope useSession() / useUser() hooks, with useDescope() for actions
- Backend
client.sessions.authenticate() / client.sessions.authenticateJwt() โ Descope backend validateSession() + an adapter returning the shape callers expect
- Stytch session cookies (
stytch_session, stytch_session_jwt) โ Descope signed session JWT in DS / DSR cookies
- Stytch magic-link / OAuth callback route (
client.magicLinks.authenticate() / client.oauth.authenticate()) โ removed/rewritten; Descope completes auth client-side
Backend SDKs
Node.js
Stytch SDK: stytch (stytch-node) โ Descope @descope/node-sdk
- Remove
stytch auth/session usage; add @descope/node-sdk
- Replace
client.sessions.authenticateJwt() / client.sessions.authenticate() with custom middleware calling descopeClient.validateSession(sessionToken) against the DS cookie (parse the cookie yourself)
Python
Stytch SDK: stytch (stytch-python) โ Descope descope Python SDK
- Remove the Stytch Python SDK auth/session usage; add the
descope Python SDK
- Validate the
DS session token with descope_client.validate_session(session_token=session_token) (or validate against Descope's JWKS for a custom authorizer)
Go
Stytch SDK: stytch-go โ Descope Go SDK github.com/descope/go-sdk
- Remove the Stytch Go SDK; add
descope/go-sdk
- Session validation:
descopeClient.Auth.ValidateSessionWithToken(ctx, token) returns (bool, *descope.Token, error)
- Stytch
organization_id โ a Descope tenant ID: pass it to management calls (descopeClient.Management.Tenant() / user-tenant association); at request time read tenant context off the returned *descope.Token (token.GetTenants(), or the dct claim for the active tenant)
Ruby
Stytch SDK: stytch-ruby โ Descope Ruby SDK
- Remove the Stytch Ruby SDK; add the Descope Ruby SDK
- Validate the
DS session token with descope_client.validate_session(session_token: session_token) in your request lifecycle
- No dedicated recipe in
implementation-nuances.md yet โ follow the Node.js / Python backend patterns and verify against the Descope Ruby SDK.
Java / Kotlin (JVM)
Stytch SDK: stytch-java (Java/Kotlin/JVM) โ Descope descope-java
- Remove the Stytch Java SDK; add
descope-java
- Validate the
DS token via a filter/interceptor: authenticationService.validateSessionWithToken(sessionToken) returns a Token
- No dedicated recipe yet โ follow the backend patterns and verify against the Descope Java SDK.
Frontend SDKs
Read the session the framework-native way โ never hand-parse the JWT on the client. On
front-end pages and components, get auth state from the Descope hooks: useSession() for the
session token and auth status, useUser() for the user profile, and useDescope() for actions
like logout(). Do not manually decode the session token or pull claims out of it in client
code. Server-side session validation โ session() in @descope/nextjs-sdk/server,
validateSession() in @descope/node-sdk (or the other backend SDKs) โ belongs only in backend
routes, middleware, and API handlers, never in a rendered client component. This matters
most with the React SDK, where it's tempting to crack open the raw token in a component instead
of calling useUser() / useSession().
Vanilla JS
Stytch SDK: @stytch/vanilla-js โ Descope @descope/web-js-sdk + @descope/web-component
- Stytch headless client (
createStytchUIClient / StytchHeadlessClient) session access โ @descope/web-js-sdk (getSessionToken(), isJwtExpired(), refresh())
- Stytch UI login โ
<descope-wc project-id flow-id> web component, listening for success / error events
- Logout:
sdk.logout() + clear stored tokens/cookies
React
Stytch SDK: @stytch/react โ Descope @descope/react-sdk
<StytchProvider> โ Descope <AuthProvider projectId>
- Stytch UI (
<StytchLogin>) / headless useStytch() login โ embedded <Descope flowId> component, wiring onSuccess
useStytchSession() / useStytchUser() โ Descope useSession() + useUser() hooks, with useDescope() for actions
- Always read auth state through the hooks โ never decode the session token by hand in a component, and never call backend
validateSession() from client code; that runs only on the server.
- Logout:
sdk.logout() via useDescope() hook
- No dedicated recipe yet โ follow the Next.js client-side patterns and verify each method against docs.
Next.js
Stytch SDK: @stytch/nextjs โ Descope @descope/nextjs-sdk + @descope/node-sdk
@stytch/nextjs โ @descope/nextjs-sdk + @descope/node-sdk
<StytchProvider> โ Descope AuthProvider (takes projectId; must use NEXT_PUBLIC_ prefix)
- Server
client.sessions.authenticateJwt() โ session() (server); client useStytchSession() / useStytchUser() โ useSession() / useUser()
- Remove the Stytch magic-link / OAuth callback route โ verify Descope's client-side handling
- Stytch session middleware โ Descope
authMiddleware(options)
- Logout:
sdk.logout() via useDescope() hook + clear cookies (two-step)
- Client vs. server session access โ
session() from @descope/nextjs-sdk/server is server-only; useSession()/useUser() from @descope/nextjs-sdk/client are client-only. Using session() in a client component compiles but throws at runtime. Verify exact exports before writing imports.
Mobile SDKs
React Native
Stytch SDK: @stytch/react-native โ Descope @descope/react-native-sdk
- Stytch UI / headless client login โ run a Descope Flow via the React Native SDK (or hosted Flow)
- Stytch session access/storage โ Descope React Native SDK session management
- Logout: Descope SDK logout + clear the stored session
- No dedicated recipe yet โ verify methods against the Descope React Native SDK.
iOS (Swift)
Stytch iOS Swift SDK โ Descope descope-swift
- Stytch login (UI or headless) โ run a Descope Flow via the Swift SDK, or hosted Flow
- Stytch session validation/refresh โ Descope Swift SDK session APIs
- No dedicated recipe yet โ verify against the Descope Swift SDK.
Android (Kotlin)
Stytch Android Consumer SDK (headless Kotlin Multiplatform) โ Descope descope-kotlin
- Headless Stytch client login โ run a Descope Flow via the Android/Kotlin SDK, or hosted Flow
- Stytch session validation/refresh โ Descope Kotlin SDK session APIs
- No dedicated recipe yet โ verify against the Descope Android/Kotlin SDK.
After completing framework code changes: Update MIGRATION-STATE.md โ mark each
modified file as Done in the Files Inventory, update Current Phase and Next Action, and
log any non-obvious decisions made (adapter types kept, async cascade scope, etc.).
Step 2.5: Non-Code File Updates
Scan for Stytch references in non-code files after updating source files.
.env.example / .env.template / .env.sample
# REMOVE
STYTCH_PROJECT_ID=
STYTCH_SECRET=
STYTCH_PUBLIC_TOKEN=
NEXT_PUBLIC_STYTCH_PUBLIC_TOKEN=
# ADD
DESCOPE_PROJECT_ID= # Console โ Project Settings
NEXT_PUBLIC_DESCOPE_PROJECT_ID= # Next.js / frontend โ same value as above
DESCOPE_MANAGEMENT_KEY= # Console โ Company โ Management Keys (replaces STYTCH_SECRET for admin APIs)
Run grep -ir "STYTCH" to find all env var references โ .env.example, Docker, CI, shell scripts.
README / docs
Search all .md files for Stytch references. At minimum, update:
- Setup section โ replace "create a Stytch app" instructions with Descope Console setup steps
- Environment variables section โ reflect the reduced env var set
- Run instructions โ replace Stytch dashboard steps with Descope Console steps
- Auth flow diagrams or descriptions โ update to reflect Descope's cookie-based approach
Docker / CI files
Check Dockerfile, docker-compose.yml, .github/workflows/, and any CI config for
STYTCH_* env var declarations. Update them to DESCOPE_*.
Setup / bootstrap scripts
When the migration includes a setup or seed script (e.g., scripts/bootstrap.mjs, scripts/seed.ts), split it into two parts:
- Console setup (cannot be scripted): Flows, email templates, MFA configuration, branding/Styles, SSO Setup Suite โ configure these in the Descope Console. Represent them as a Phase 1 checklist in
MIGRATION-PLAN.md.
- SDK automation (can be scripted): role creation (
management.role.create()), tenant creation, access key provisioning, SSO/SCIM config. Preserve these as a Node.js/Python script using the Descope Management SDK.
After completing non-code file updates: Update MIGRATION-STATE.md โ mark env files,
README, and CI config done in the Files Inventory, and advance Next Action.
Step 3: Feature Migration Mapping
For each Stytch feature confirmed in triage, write a short paragraph: what it accomplishes, the
best Descope approach for that goal, what's different, and what action is required. Reason about
intent, not just the API surface โ the best approach may be a Flow, Widget, SSO Setup Suite, Inbound
App, Console configuration, or tenant configuration rather than a direct SDK equivalent.
Only recommend SDK/API code when programmatic control is genuinely required, and verify every method
name against the Descope MCP server before writing it. Include only confirmed features.
Consumer Authentication โ Descope Flows + Auth Methods + JWT Templates
Stytch Consumer Auth handles B2C sign-in โ hosted/prebuilt UI, frontend SDK flows, backend API
flows, users, sessions, and methods (OAuth/social, magic links, OTP, passwords, passkeys/WebAuthn,
mobile biometrics, MFA/TOTP, crypto wallet). Descope maps these to Flows, authentication methods,
Users, session validation, and JWT Templates / custom claims.
| Stytch | Descope |
|---|
| Stytch UI / prebuilt login UI | Descope Flows |
| Frontend SDK auth flows | Descope frontend SDK + Flow component |
| Backend API-driven auth | Descope backend SDK / API auth methods when Flows are not sufficient |
| OAuth/social login | Descope OAuth/social login methods |
| Email magic links | Descope Magic Link / Enchanted Link |
| Email/SMS/WhatsApp OTP | Descope OTP methods |
| Passwords | Descope Passwords |
| Passkeys / WebAuthn | Descope Passkeys |
| TOTP / MFA | Descope MFA / TOTP / Flow conditions |
| Stytch User object | Descope User |
| Stytch session token / session JWT | Descope session token / JWT + backend session validation |
| Stytch custom claims / session metadata | Descope JWT Templates or Custom Claims action |
Prefer Flows for the user journey; use custom SDK/API calls only when Flows cannot express the
requirement. Confirm which Stytch methods are enabled, whether Stytch or custom UI is used, and
whether backend routes call Stytch APIs directly. Effort: LowโMedium for straightforward B2C
auth; higher with custom session claims, MFA branching, or nonstandard factors.
Multi-tenant / B2B Authentication โ Descope Tenants + Users
Stytch B2B authentication is built around Organizations and Members. Descope maps this model
most closely to Tenants and Users associated with tenants. A Stytch Organization usually
becomes a Descope Tenant, while a Stytch Member usually becomes a Descope User with tenant membership,
roles, permissions, and tenant-specific attributes.
| Stytch | Descope |
|---|
| Organization | Tenant |
| Member | User associated with a tenant |
| Organization ID | Tenant ID |
| Organization metadata | Tenant customAttributes |
| Member metadata | User custom attributes or tenant-specific user metadata |
| Organization-specific auth settings | Tenant settings + Flow logic + SSO configuration |
| Member invitations | Invitation Flow / management SDK flow |
| Organization discovery | Tenant discovery / tenant selection / domain-based routing |
| Org-specific login | Tenant-specific login route, tenant slug, or tenant Flow input |
| Organization session exchange / org switching | Active tenant selection and tenant-aware session claims |
| Members belonging to multiple Organizations | Users belonging to multiple tenants |
Confirm the one-Stytch-Organization-to-one-Descope-Tenant mapping before writing code. This mapping
ripples into SSO, SCIM, RBAC, JIT provisioning, sessions, custom claims, and domain routing. Also
check whether the application treats organization_id as an authorization boundary, a billing
boundary, a data partition key, or all three. Effort: Medium โ conceptually clean, but application
code often assumes Stytch's Organization/Member object shapes.
Organizations and Members โ Descope Tenant and Users
Stytch Organizations and Members are not just data objects; they may drive onboarding, invitations,
membership updates, deactivation, organization switching, metadata, and tenant-specific access
controls. In Descope, model these workflows using Tenants, Users, tenant membership, roles,
permissions, and optionally Flows or management SDK calls for lifecycle operations.
| Stytch | Descope |
|---|
| Create/update Organization | Create/update Tenant |
| Create/update Member | Create/update User and tenant association |
| Organization metadata | Tenant custom attributes |
| Member metadata | User custom attributes / tenant-specific user attributes |
| Member invite | Invite/onboarding Flow or management SDK |
| Member deactivate/delete | User deactivation, tenant removal, or tenant-role removal |
| Organization allowed auth methods | Tenant settings + Flow conditions |
| Organization-specific MFA policy | Tenant-aware MFA logic in Flows |
Ask whether Organization and Member data is synchronized into the app database, whether the app reads
Stytch as the source of truth, and whether lifecycle changes trigger webhooks. Effort: Medium โ
especially if membership state is mirrored in the application database.
Enterprise SSO โ Descope Tenant SSO
Stytch Enterprise SSO maps to Descope tenant-level SSO. In Stytch, SSO connections are associated
with Organizations. In Descope, SSO is configured per Tenant, with support for SAML/OIDC providers,
domain-based routing, SSO Setup Suite, and multiple SSO providers per tenant when needed.
Preferred approach โ SSO Setup Suite: before migrating any Stytch SSO management code, ask whether
the no-code SSO Setup Suite removes the need for that code. It guides tenant admins through per-tenant
SAML/OIDC setup with IdP-specific instructions (Okta, Microsoft Entra ID, Google Workspace, etc.) and can reduce engineering involvement for new
enterprise customer onboarding.
Multiple SSO configurations per tenant. If a single Stytch customer has multiple SSO connections,
or if the old Stytch model used multiple Organizations to represent one customer with multiple IdPs,
do not blindly create multiple Descope Tenants. First decide whether the customer should become one
Descope Tenant with multiple SSO configurations.
| Stytch | Descope |
|---|
| Organization SSO connection | Tenant SSO configuration |
| SAML SSO | Descope SAML SSO |
| OIDC SSO | Descope OIDC SSO |
| Organization-specific SSO routing | Tenant routing / SSO domain routing |
| Multi-Organization SSO behavior | Tenant design + active tenant/session model review |
| Customer-admin SSO setup | SSO Setup Suite |
| SSO claim/group role assignment | SSO attribute mapping / group-to-role mapping |
| Programmatic SSO connection management | Descope Management API / SDK, if self-service is not used |
Use AskUserQuestion to ask two things here:
- Does any single customer use multiple IdPs or multiple Stytch Organizations to represent the
same real-world customer?
- Does the app need programmatic SSO configuration, or do customer admins configure SSO
themselves?
For runtime login, prefer Descope's SSO-specific login path rather than generic social OAuth logic.
The exact SDK method names differ by language/framework, so verify against the Descope MCP server
before writing implementation code. Rule of thumb: tenant/enterprise SSO should use Descope's
tenant-level SSO configuration; social login should use OAuth/social auth methods. Effort: Medium
SCIM โ Descope SCIM / Tenant Provisioning
Stytch SCIM maps to Descope SCIM provisioning. Treat this as a continuing
provisioning pipeline, not a one-time import โ enterprise directories keep pushing create, update,
group, and deprovisioning events after cutover.
| Stytch SCIM | Descope |
|---|
| SCIM endpoint per Organization | Descope SCIM endpoint / token per tenant |
| User create/update/deactivate | Tenant user provisioning lifecycle |
| Groups | External groups / group-to-role mapping |
| SCIM group-to-role assignment | SCIM or SSO group mapping to Descope roles |
| Deprovisioning | User deactivation / tenant access removal behavior |
| SCIM tokens | Tenant-scoped SCIM-compatible access keys |
| SCIM webhooks / downstream sync handlers | Descope events, audit logs, webhooks, or app sync code |
Identify every connected directory, which IdPs are used, whether groups are synced, whether groups map
to roles, and what happens when a user is removed from a group. Pay special attention to
whether Stytch deprovisioning revoked sessions immediately, removed membership, changed roles, or only
updated status. Effort: MediumโHigh โ lifecycle, groups, deprovisioning, and role mapping can be
subtle.
Admin Portal โ Descope SSO Setup Suite / Admin Widgets
Stytch Admin Portal provides customer-admin workflows for managing enterprise configuration such as
SSO, SCIM, organization settings, members, and related admin tasks. Do not default to rebuilding these
screens as custom code.