Jon Schwartz
12/23/2025, 5:01 PMThread - Anonymous User Creation --> Conversion to Authenticated UserJon Schwartz
12/23/2025, 5:02 PManonymous-user-conversion flow/screen?
I specifically want to ensure that the sub persists between generating the anonymous user JWT and authenticating the user in anonymous-user-conversion flow, but for some reason, the JWT (stored in a cookie atm) is regenerated and contains a different sub when the user authenticates.
For reference, I started this thread in #C07P7AN1EQH, but no luck so far.Meir Wahnon
12/23/2025, 5:26 PMAviad Lichtenstadt
12/23/2025, 5:54 PMJon Schwartz
12/23/2025, 7:09 PMcreate-anonymous-user-with-custom-information flow (to create the anonymous user) in tandem with the anonymous-user-conversion flow (to authenticate the user), which was working. Both of those are using the Descope component from @descope/nextjs-sdk.
---
However, I need a bit more flexibility so I created an API route (I've named it /create-anonymous-user) which uses the @descope/node-sdk to create an anonymous user and have paired that with the Descope component from the @descope/nextjs-sdk
// "/create-anonymous-user" API route
try {
const client = DescopeClient({ projectId, managementKey });
const resp = await client.management.jwt.anonymous({});
if (!resp.ok || !resp.data?.sessionJwt) {
return NextResponse.json({ success: false, error: "Failed to create session" }, { status: 500 });
}
// httpOnly: false so Descope SDK can read it
cookieStore.set("DS", resp.data.sessionJwt, {
httpOnly: false,
secure: process.env.NODE_ENV === "production",
sameSite: "lax",
path: "/",
});
return NextResponse.json({ success: true });
// <Descope /> component:
<DescopeFlowStep
flowId="anonymous-user-conversion"
redirectUrl={redirectUrl}
onSuccess={handleAuthSuccess}
/>Meir Wahnon
12/23/2025, 7:41 PMNick Rodriguez
12/23/2025, 7:45 PMJon Schwartz
12/23/2025, 8:11 PMNick Rodriguez
12/23/2025, 8:18 PMsessionTokenViaCookie={true} is enabled in your Descope provider. Ref: https://docs.descope.com/auth-methods/oauth/with-sdks/client#import-and-initialize-sdk
• Confirm the cookie name lines up everywhere (default is DS) — backend, frontend config, and the flow End Action if customized.
• Make sure the cookie is accessible to the flow (domain/path/baseUrl match, especially if using a custom domain).
• Right before rendering the anonymous-user-conversion flow, it’s worth verifying the SDK sees the anonymous JWT (with danu: true) rather than an empty/new session. Ref: https://docs.descope.com/management/user-management/anonymous-users#creating-an-anonymous-user
If the flow can see the anonymous JWT at the start, it should convert it and retain the same subject.Jon Schwartz
12/23/2025, 9:15 PManonymous-user-conversion flow can't detect the anon user's JWT. I will go through these suggestions and see if I can get it up-and-running