stack/apps/backend/src/lib
BilalG1 512099ed23
Speed up dummy-project seeding (preview create-project ~15s → ~1.3s) (#1437)
## Summary

The internal `preview/create-project` endpoint was taking ~15s because
`seedDummyProject` created its dummy users one at a time through the
full `usersCrudHandlers.adminCreate` CRUD pipeline (one DB transaction +
config render per user, ~86 users). This reworks the seeding path to use
bulk inserts.

End-to-end, the endpoint's server-side handler time drops from
**~15,100ms → ~1,300ms** (~11× faster).

## Seeding changes (`seed-dummy-data.ts`)

- **`seedDummyUsers` — bulk insert.** Build every row (`ProjectUser`,
`ContactChannel`, `AuthMethod`, `ProjectUserOAuthAccount`,
`OAuthAuthMethod`, default permissions) up front with pre-generated
UUIDs, then insert via one `createMany` per table inside a single
transaction — replacing ~86 sequential `adminCreate` transactions.
Named-user team memberships are bulk-inserted the same way (`TeamMember`
+ `TeamMemberDirectPermission`). Idempotency is preserved with a single
up-front email lookup, so re-runs against an existing project still skip
existing users.
- **Native `randomUUID`.** The seed paths now use `node:crypto`'s
`randomUUID()` instead of stack-shared's `generateUuid()`. The
browser-safe polyfill calls `crypto.getRandomValues` ~31× per UUID (once
per template char, each with a fresh `Uint8Array(1)`); generating
thousands of seed UUIDs made that ~800ms of pure CPU in the
activity-event build alone.
- **`seedBulkSignupsAndActivity`.** Skip the redundant back-date
`UPDATE` for freshly-inserted users (`createMany` already writes correct
`createdAt`/`signedUpAt`), and flush ClickHouse events in larger,
parallel batches.
- **`seedDummyProject`.** Run `seedBulkSignupsAndActivity` concurrently
with the lighter remaining steps, and fold `seedDummyTransactions` into
the emails/activity/replays `Promise.all`.
- Removed the now-unused `syncSeedUserOauthProviders` helper.

The bulk path produces the same rows as the CRUD-handler path (verified
row-count equality during development). Webhooks / soft-limit checks are
intentionally not fired for seed data, consistent with the rest of the
seed.

## Also in this PR — preview-mode 404 fix
(`preview-project-redirect.tsx`)

While testing the above, the dashboard 404'd right after a preview
project was created. In preview mode the `/projects` page renders
`PreviewProjectRedirect`, which `POST`s
`/internal/preview/create-project` and then `router.push()`es to
`/projects/<new-id>` — but it never refreshed the client-side
owned-projects cache, so the `[projectId]` route's `useAdminApp()` read
a stale list, failed to find the just-created project, and called
`notFound()`.

Fixed by refreshing the owned-projects cache before navigating, matching
what the normal create-project flow in `page-client.tsx` already does.
(Pre-existing bug, not caused by the seeding change — but it surfaces
the seeding path, so it's bundled here.)

## Testing

`pnpm typecheck` and `pnpm lint` pass for both backend and dashboard.
The preview endpoint was exercised repeatedly during development (HTTP
200, projects created and populated correctly).

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

* **Performance**
* Much faster bulk user and event seeding via larger, parallelized
batches and optimized backfilling.

* **Refactor**
* Dummy data seeding redesigned to be idempotent, deterministic, and
bulk-oriented; seeding tasks now overlap where safe.

* **Bug Fixes**
* Preview project flow validates client capabilities and refreshes the
local project list to avoid stale navigation.
  * Auto-login guarded to run only once to prevent duplicate sign-ins.

* **UI/UX**
* Walkthrough steps and sidebar behavior improved; walkthrough labels
and search keywords updated.

* **Chore**
* CLI identity command now resolves session authentication more
reliably.

<!-- review_stack_entry_start -->

[![Review Change
Stack](https://storage.googleapis.com/coderabbit_public_assets/review-stack-in-coderabbit-ui.svg)](https://app.coderabbit.ai/change-stack/hexclave/stack-auth/pull/1437?utm_source=github_walkthrough&utm_medium=github&utm_campaign=change_stack)

<!-- review_stack_entry_end -->
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2026-05-20 10:10:22 -07:00
..
ai Move internal MCP server to backend, use Mintlify MCP for docs tools (#1389) 2026-04-29 09:45:52 -07:00
bulldozer Make Bulldozer SQL statements deterministic 2026-04-18 16:43:26 -07:00
payments payments: rework refund flow to three-knob API (#1429) 2026-05-15 19:29:21 -07:00
cache.tsx Upgrade Prisma to v7 (#1064) 2025-12-26 08:13:34 -08:00
cel-evaluator.ts Turnstile integration for fraud protection (#1239) 2026-03-20 21:26:45 +00:00
clickhouse-errors.ts Classify ClickHouse NO_COMMON_TYPE (386) as unsafe (#1380) 2026-04-24 12:07:16 -07:00
clickhouse.tsx Increase Clickhouse request timeout 2026-04-18 21:46:10 -07:00
config.tsx Fix flaky tests and preexisting CI failures (#1443) 2026-05-20 10:00:11 -07:00
contact-channel.tsx External db sync (#1036) 2026-02-05 12:04:31 -08:00
conversation-types.ts [Apps] Adding support app alpha and dogfooding (#1368) 2026-05-13 11:36:11 -05:00
conversations-api.ts [Apps] Adding support app alpha and dogfooding (#1368) 2026-05-13 11:36:11 -05:00
conversations.tsx [Apps] Adding support app alpha and dogfooding (#1368) 2026-05-13 11:36:11 -05:00
dev-perf-stats.tsx Fix dev-perf-stats 2026-02-04 13:59:31 -08:00
dev-request-stats.tsx Fix dev stats accuracy 2025-12-29 17:15:08 +01:00
development-environment.ts Remote dev envs (#1435) 2026-05-19 15:54:18 -07:00
email-delivery-stats.tsx [Refactor][Feat][Fix] Rework Email Section With New Sent Page, Better Drafts Page, and Settings Page (#1221) 2026-03-11 12:01:36 -07:00
email-drafts.tsx fix types 2025-12-26 18:11:37 +01:00
email-queue-step.test.tsx fix(email-queue): recover stuck sending without duplicate retry (#1356) 2026-04-24 11:00:46 -07:00
email-queue-step.tsx Fix flaky tests and preexisting CI failures (#1443) 2026-05-20 10:00:11 -07:00
email-rendering.test.tsx [Refactor][Feat][Fix] Rework Email Section With New Sent Page, Better Drafts Page, and Settings Page (#1221) 2026-03-11 12:01:36 -07:00
email-rendering.tsx Improved StackAssertionError error logging 2026-05-07 13:29:01 -07:00
email-template-rewrite.ts Custom dashboards and unified ai no playground (#1243) 2026-03-13 20:24:40 +00:00
emailable.tsx Add more error messages for 249 Emailable errors 2026-04-09 11:06:27 -07:00
emails-low-level.tsx [Refactor] Make all SMTP 4yz Errors Retryable (#1293) 2026-04-07 16:20:39 +00:00
emails.tsx Backend fallback (cloud run) (#1306) 2026-04-11 00:57:37 +00:00
end-users.tsx Backend fallback (cloud run) (#1306) 2026-04-11 00:57:37 +00:00
events.tsx Improved StackAssertionError error logging 2026-05-07 13:29:01 -07:00
external-db-sync-metadata.ts [Refactor] Improve CI Run Times by Reducing Test Flakiness and Speeding up Test Suite (#1166) 2026-02-10 19:43:10 -08:00
external-db-sync-queue.ts [Fix] recover stale external db requests (#1428) 2026-05-12 17:55:44 -07:00
external-db-sync.ts clickhouse new syncs and verify-data (#1304) 2026-04-08 14:43:22 -07:00
featurebase.tsx Replace Web3Forms with internal feedback emails (#1244) 2026-03-23 17:07:37 -07:00
images.tsx Project logo upload (#817) 2025-08-19 04:45:16 +02:00
internal-api-keys.tsx "Require publishable client key" toggle (#1158) 2026-02-19 10:23:16 -08:00
internal-feedback-emails.tsx dev tool indicator (#1272) 2026-04-13 17:43:03 -07:00
js-execution.tsx Improved StackAssertionError error logging 2026-05-07 13:29:01 -07:00
local-emulator.test.ts Remote dev envs (#1435) 2026-05-19 15:54:18 -07:00
local-emulator.ts Remote dev envs (#1435) 2026-05-19 15:54:18 -07:00
managed-email-domains.tsx Redesign Email Server settings + managed domain flow (#1373) 2026-04-24 13:35:03 -07:00
managed-email-onboarding.tsx Redesign Email Server settings + managed domain flow (#1373) 2026-04-24 13:35:03 -07:00
metrics-activity-split.ts Overview revamp (#1238) 2026-04-15 09:36:00 -07:00
notification-categories.ts Email outbox backend (#1030) 2025-12-12 10:26:38 -08:00
oauth.tsx Turnstile integration for fraud protection (#1239) 2026-03-20 21:26:45 +00:00
openapi.tsx Data-grid overhaul + session-replays / team-payments dashboard surfaces (#1424) 2026-05-15 14:16:47 -07:00
payments.test.tsx payments: rework refund flow to three-knob API (#1429) 2026-05-15 19:29:21 -07:00
payments.tsx [Refactor] [Fix] Remove default prod creation (#1350) 2026-05-15 10:38:33 -07:00
permissions.tsx clickhouse new syncs and verify-data (#1304) 2026-04-08 14:43:22 -07:00
plan-entitlements.test.ts [Feat]: set flag to disable billing (#1417) 2026-05-06 14:58:06 -07:00
plan-entitlements.ts [Feat]: set flag to disable billing (#1417) 2026-05-06 14:58:06 -07:00
preview-mode.ts stack auth preview mode (#1307) 2026-04-08 16:57:42 -07:00
product-versions.tsx [Fix] [Refactor] Implement Base Settings for Stack-Auth Plans and Move Metadata from Stripe Webhook Event to Table (#1214) 2026-02-23 22:09:27 -08:00
projects.tsx Remote dev envs (#1435) 2026-05-19 15:54:18 -07:00
redirect-urls.test.tsx [Fix] [Feat] Update OAuth Sign-In and Get Token Functions to Work (#1130) 2026-01-28 02:17:27 +00:00
redirect-urls.tsx [Fix] [Feat] Update OAuth Sign-In and Get Token Functions to Work (#1130) 2026-01-28 02:17:27 +00:00
request-checks.tsx Upgrade Prisma to v7 (#1064) 2025-12-26 08:13:34 -08:00
risk-scores.tsx rework weights for same name signups (#1298) 2026-04-12 23:30:55 +00:00
seed-dummy-data.test.ts [codex] Fix preview dummy payments customer types (#1398) 2026-05-01 09:44:30 -07:00
seed-dummy-data.ts Speed up dummy-project seeding (preview create-project ~15s → ~1.3s) (#1437) 2026-05-20 10:10:22 -07:00
session-replays.tsx Analytics event tracking (#1208) 2026-02-17 18:33:01 -08:00
sign-up-context.ts Turnstile integration for fraud protection (#1239) 2026-03-20 21:26:45 +00:00
sign-up-heuristics.tsx Turnstile integration for fraud protection (#1239) 2026-03-20 21:26:45 +00:00
sign-up-rules.ts [Refactor][Feat] Implement Plan Limits for Hard-and-Soft Item Caps (#1215) 2026-05-04 18:25:13 -07:00
stripe-proxy.tsx one time payments (#865) 2025-09-12 17:14:09 -07:00
stripe.tsx Improved StackAssertionError error logging 2026-05-07 13:29:01 -07:00
telegram.tsx payment email templates (#1106) 2026-01-20 18:45:01 -08:00
tenancies.tsx Make most queries readonly 2026-01-02 04:25:05 +01:00
tokens.tsx [Refactor][Feat] Implement Plan Limits for Hard-and-Soft Item Caps (#1215) 2026-05-04 18:25:13 -07:00
turnstile.tsx Turnstile integration for fraud protection (#1239) 2026-03-20 21:26:45 +00:00
types.tsx Upgrade Prisma to v7 (#1064) 2025-12-26 08:13:34 -08:00
upstash.tsx local emulator security and features fixes (#1247) 2026-04-14 15:36:24 -07:00
users.tsx Enhance error handling and logging in Emailable response validation (#1292) 2026-04-01 09:21:43 -07:00
webhooks.tsx stack auth preview mode (#1307) 2026-04-08 16:57:42 -07:00