stack icon indicating copy to clipboard operation
stack copied to clipboard

How can I enable anonymous account sign‑up for my own Stack Auth project?

Open nexa-li opened this issue 8 months ago • 2 comments

I’m self‑hosting Stack Auth (latest main branch).
When I call the anonymous sign‑up endpoint

POST /api/v1/auth/anonymous/sign-up

the API responds with

{
  "code": "ANONYMOUS_ACCOUNTS_NOT_ENABLED",
  "error": "Anonymous accounts are not enabled for this project."
}

What I tried / observations • I located the route handler at apps/backend/src/app/api/latest/auth/anonymous/sign-up/route.ts. It has a hard‑coded whitelist:

// Define the allowed project IDs for anonymous sign‑up
const ALLOWED_PROJECT_IDS = [
  "9bee8100-8d83-4ad7-aaad-d6607e386a28",
  "71bd203a-14d9-4ccc-b704-32bfac0e2542",
  "internal",
];

My own project UUID is obviously not in that list, so the endpoint throws KnownErrors.AnonymousAccountsNotEnabled.

Expected result

The API should create an anonymous user record and return access_token, refresh_token, and user_id, just like it does for the two whitelisted demo projects.

Actual result

Error response as shown above.

Questions 1. Is there a documented way (env var, dashboard toggle, database flag, etc.) to enable anonymous sign‑up for custom projects? 2. If this feature is intentionally limited to internal/demo projects for now, is there a recommended workaround (e.g., fork & remove the ALLOWED_PROJECT_IDS check) or an ETA for official support?

Thanks a lot for the awesome project! Happy to test any beta fixes or open a PR if guidance is provided. 🙌

nexa-li avatar Apr 21 '25 04:04 nexa-li

Until an official switch exists, I enabled anonymous sign‑up by cloning my project record to a UUID that lives inside the current ALLOWED_PROJECT_IDS list and then updating every FK reference.
The one‑off SQL I used is below—replace old-id / new-id with your own values:

BEGIN;

-- 1. Copy the Project row, changing only the primary key
INSERT INTO "Project" (
  "id",
  "createdAt",
  "updatedAt",
  "displayName",
  "description",
  "configId",
  "isProductionMode",
  "userCount"
)
SELECT
  'new-id',           -- new primary key (must be whitelisted for now)
  "createdAt",
  "updatedAt",
  "displayName",
  "description",
  "configId",
  "isProductionMode",
  "userCount"
FROM "Project"
WHERE "id" = 'old-id';

-- 2. If a NeonProvisionedProject row exists, clone it
INSERT INTO "NeonProvisionedProject" (
  "projectId",
  "createdAt",
  "updatedAt",
  "neonClientId"
)
SELECT
  'new-id',
  "createdAt",
  "updatedAt",
  "neonClientId"
FROM "NeonProvisionedProject"
WHERE "projectId" = 'old-id';

-- 3. Update every FK that referenced the old project
UPDATE "ApiKeySet"        SET "projectId" = 'new-id' WHERE "projectId" = 'old-id';
UPDATE "ProjectApiKey"    SET "projectId" = 'new-id' WHERE "projectId" = 'old-id';
UPDATE "VerificationCode" SET "projectId" = 'new-id' WHERE "projectId" = 'old-id';
UPDATE "Tenancy"          SET "projectId" = 'new-id' WHERE "projectId" = 'old-id';

-- tables that store the ID in `mirroredProjectId`
UPDATE "ProjectUser" SET "mirroredProjectId" = 'new-id' WHERE "mirroredProjectId" = 'old-id';
UPDATE "Team"       SET "mirroredProjectId" = 'new-id' WHERE "mirroredProjectId" = 'old-id';

-- 4. Clean up the old records
DELETE FROM "NeonProvisionedProject" WHERE "projectId" = 'old-id';
DELETE FROM "Project"                WHERE "id"        = 'old-id';

COMMIT;

After running this, I also added the new project UUID to the server metadata of my admin account so the dashboard recognise it.

Obviously this is just a stop‑gap and will break if the allowed‑IDs list changes, so a proper config flag or dashboard toggle would be much appreciated! 🙏

nexa-li avatar Apr 21 '25 04:04 nexa-li

This feature is not fully complete yet, which is why we only rolled it out to a few alpha users. We will soon make it a public release with full docs and more features.

fomalhautb avatar May 12 '25 17:05 fomalhautb