feat: complete removal of Clerk — DB schema, dead code, configs, frontend, OpenAPI, CI#1585
Conversation
…tend, OpenAPI Agent-Logs-Url: https://github.com/jaypatrick/adblock-compiler/sessions/9ee55884-527b-456f-8dc9-1ae659879406 Co-authored-by: jaypatrick <1800595+jaypatrick@users.noreply.github.com>
🗄️ Database Migration Plan
📂 Changed Migration FilesMain DB (
☁️ Cloudflare D1Main Database (
|
|
@copilot Run pnpm install --frozen-lockfile |
…eon-branch-create workflow Agent-Logs-Url: https://github.com/jaypatrick/adblock-compiler/sessions/af0e4416-4af5-4f25-a721-126c8344abd9 Co-authored-by: jaypatrick <1800595+jaypatrick@users.noreply.github.com>
Fixed in commit |
🐘 Neon Database Branch Created
🔗 Connection string (click to expand)
ℹ️ What is this?This PR has an isolated Neon database branch that is a copy-on-write See docs/database-setup/neon-branching.md for details. |
There was a problem hiding this comment.
Pull request overview
Removes the remaining legacy Clerk integration across DB schema, worker, frontend, OpenAPI/docs, and CI, completing the migration to Better Auth and cleaning up stale/generated artifacts.
Changes:
- Drops Clerk-specific columns/indexes from D1 (
users.clerk_user_id,agent_sessions.clerk_user_id) and updates Prisma schemas + regenerated clients. - Removes stale session
tokenHashusage from storage schemas/adapter and updates tests. - Cleans up Clerk references across worker/frontend/docs/postman and aligns CI pnpm/node setup.
Reviewed changes
Copilot reviewed 51 out of 58 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| worker/services/user-service.ts | Deletes Clerk-only user CRUD service. |
| worker/services/user-service.test.ts | Deletes tests for the removed Clerk user service. |
| worker/services/feature-flag-service.ts | Updates docs to reference Better Auth instead of Clerk. |
| worker/services/admin-logger.ts | Updates field docs to remove Clerk wording. |
| worker/services/admin-feature-flag-service.ts | Updates JSDoc createdBy wording to Better Auth. |
| worker/services/admin-config-service.ts | Updates JSDoc createdBy wording to Better Auth. |
| worker/services/admin-audit-service.ts | Updates audit docs to remove Clerk wording. |
| worker/services/admin-analytics-events.ts | Updates analytics event docs to remove Clerk wording. |
| worker/handlers/admin-handlers.ts | Removes legacy clerk_user_id query param fallback. |
| src/storage/schemas.ts | Removes tokenHash from CreateSessionSchema. |
| src/storage/schemas.test.ts | Updates schema tests to reflect removal of tokenHash. |
| src/storage/HyperdriveStorageAdapter.ts | Stops writing tokenHash on session creation. |
| src/storage/HyperdriveStorageAdapter.test.ts | Updates adapter tests to remove tokenHash usage. |
| src/diagnostics/IDiagnosticsProvider.ts | Updates diagnostics user-id docs to Better Auth. |
| src/configuration/schemas.ts | Updates CLI bearerToken description to Better Auth. |
| src/cli/CliApp.deno.ts | Updates CLI help text to Better Auth. |
| src/cli/ArgumentParser.ts | Updates CLI help/examples to Better Auth. |
| scripts/generate-postman-collection.ts | Renames Postman variable from clerkToken to bearerToken. |
| scripts/diag-full.ts | Removes /api/clerk-config diagnostic probe. |
| prisma/schema.prisma | Removes clerkUserId field from User model. |
| prisma/schema.d1.prisma | Removes D1 clerkUserId field and updates header comment. |
| prisma/generated/models/User.ts | Regenerates Prisma types removing clerkUserId. |
| prisma/generated/models/Session.ts | Regenerates Prisma types removing tokenHash. |
| prisma/generated/models/AgentSession.ts | Regenerates Prisma types removing clerkUserId. |
| prisma/generated/internal/prismaNamespaceBrowser.ts | Regenerates Prisma internal enums removing Clerk/tokenHash fields. |
| prisma/generated/internal/prismaNamespace.ts | Regenerates Prisma internal enums removing Clerk/tokenHash fields. |
| prisma/generated-d1/models/User.ts | Regenerates D1 Prisma types removing clerkUserId. |
| prisma/generated-d1/models/LocalAuthUser.ts | Removes generated LocalAuthUser model file. |
| prisma/generated-d1/models.ts | Removes export of LocalAuthUser model. |
| prisma/generated-d1/internal/prismaNamespaceBrowser.ts | Regenerates D1 Prisma namespace removing LocalAuthUser + Clerk field enums. |
| prisma/generated-d1/internal/prismaNamespace.ts | Regenerates D1 Prisma namespace removing LocalAuthUser + Clerk field enums. |
| prisma/generated-d1/internal/class.ts | Regenerates D1 Prisma client internals after schema changes. |
| prisma/generated-d1/client.ts | Removes exported LocalAuthUser type. |
| prisma/generated-d1/browser.ts | Removes exported LocalAuthUser type. |
| postman/environments/adblock-compiler.environment.yaml | Renames Clerk env var to bearerToken and removes Clerk publishable key entry. |
| postman/environments/adblock-compiler-local.environment.yaml | Renames Clerk env var to bearerToken and removes Clerk publishable key entry. |
| migrations/0009_remove_clerk_fields.sql | Adds D1 migration to drop Clerk columns/indexes from users and agent_sessions. |
| frontend/src/assets/endpoint-registry.json | Removes /api/webhooks/clerk endpoint and updates auth tag description. |
| frontend/src/app/services/api-key.service.ts | Updates service docs to Better Auth. |
| frontend/src/app/services/agent-rpc.service.ts | Updates auth docs/comments to Better Auth only. |
| frontend/src/app/models/agent.models.ts | Updates model docs to Better Auth only. |
| frontend/src/app/guards/admin.guard.ts | Updates SSR comment to Better Auth and removes Clerk mention. |
| frontend/src/app/components/api-keys/api-keys.component.spec.ts | Renames mock service variable from Clerk to generic auth naming. |
| frontend/src/app/app.routes.server.ts | Updates auth route SSR/CSR docs to Better Auth. |
| frontend/src/app/app.config.ts | Removes Clerk mention from browser-only API comment. |
| frontend/src/app/admin/webhooks/webhooks.component.ts | Removes Clerk-specific phrasing from the webhook viewer UI copy. |
| frontend/src/app/admin/roles/roles.component.ts | Renames “Clerk User ID” label to “User ID”. |
| frontend/src/app/admin/roles/roles.component.spec.ts | Updates fixtures from clerk-* to user-* and adjusts URL expectations. |
| frontend/src/app/admin/api-keys/api-keys.component.ts | Removes clerkUserId column/details/filter from admin API keys UI. |
| frontend/src/app/admin/api-keys/api-keys.component.spec.ts | Updates tests/fixtures to remove clerkUserId filtering. |
| docs/postman/postman-environment.json | Renames clerkToken to bearerToken. |
| docs/postman/postman-collection.json | Renames token variable to bearerToken and updates auth descriptions; removes Clerk webhook request. |
| docs/api/openapi.yaml | Removes Clerk webhook path/scheme and updates auth descriptions/security references to Better Auth. |
| docs/api/cloudflare-schema.yaml | Regenerates Cloudflare schema to reflect Better Auth and removed Clerk webhook/scheme. |
| deno.lock | Updates lockfile entries after Prisma regeneration/tooling changes. |
| .github/workflows/neon-branch-create.yml | Switches to shared pnpm/node setup action and bumps Node to 22. |
| .dev.vars.example | Removes deprecated Clerk env var section. |
Comments suppressed due to low confidence (2)
docs/api/openapi.yaml:4719
securityrequirements referenceBearerAuth, butcomponents.securitySchemesdoes not define aBearerAuthscheme (onlyTurnstile,AdminKey,UserApiKey). This makes the OpenAPI document invalid for any endpoint that now lists- BearerAuth: []. Add aBearerAuthhttp bearer security scheme (or change the affected endpoints back to an existing scheme) so validation and downstream generation are consistent.
securitySchemes:
Turnstile:
type: apiKey
in: header
name: turnstileToken
description: Cloudflare Turnstile token (if enabled on the server)
AdminKey:
type: apiKey
in: header
name: X-Admin-Key
description: Admin API key for protected admin endpoints
UserApiKey:
type: http
scheme: bearer
bearerFormat: ApiKey
description: "User API key with abc_ prefix. Pass the key as a Bearer token in the Authorization header (e.g. Authorization: Bearer abc_...)."
docs/api/cloudflare-schema.yaml:4853
- This generated Cloudflare schema references
BearerAuthin multiplesecurityblocks, butcomponents.securitySchemesdoes not defineBearerAuth(onlyTurnstile,AdminKey,UserApiKey). Add the missingBearerAuthscheme (or update thesecurityblocks to use an existing scheme) to keep the schema valid and consistent withopenapi.yaml.
securitySchemes:
Turnstile:
type: apiKey
in: header
name: turnstileToken
description: Cloudflare Turnstile token (if enabled on the server)
AdminKey:
type: apiKey
in: header
name: X-Admin-Key
description: Admin API key for protected admin endpoints
UserApiKey:
type: http
scheme: bearer
bearerFormat: ApiKey
description: >-
User API key with abc_ prefix. Pass the key as a Bearer token in the Authorization header (e.g.
Authorization: Bearer abc_...).
security: []
|
@copilot apply changes based on the comments in this thread |
…search label Agent-Logs-Url: https://github.com/jaypatrick/adblock-compiler/sessions/e007a6be-5441-4be0-a9d7-a7ccea4f5dc4 Co-authored-by: jaypatrick <1800595+jaypatrick@users.noreply.github.com>
Applied all four review items in commit
|
Description
Completes the full migration from Clerk to Better Auth by removing every remaining Clerk reference across the codebase. Better Auth was already fully operational; this PR removes the dead/legacy Clerk layer.
Changes
Database (highest priority)
migrations/0009_remove_clerk_fields.sql— New D1 migration that dropsclerk_user_idfromusersandagent_sessionsvia SQLite table-recreation pattern. Removes theidx_users_clerk_user_idandidx_agent_sessions_clerk_user_idindexes. Migration follows the established pattern from0004_users_email_nullable.sql: wrapped inPRAGMA foreign_keys = OFF/ON, temp tables use underscore-prefixed names (_users_new,_agent_sessions_new) withoutIF NOT EXISTSso partial runs fail loudly, and all pre-existing indexes are recreated (includingidx_users_tier).prisma/schema.prisma— RemovedclerkUserId String? @map("clerk_user_id")from theUsermodel along with its legacy comment block.prisma/schema.d1.prisma— RemovedclerkUserId @unique @map("clerk_user_id")from D1Usermodel; updated section header from// Users — synced from Clerk webhooksto// Users.prisma/generated/+prisma/generated-d1/— Regenerated both Prisma clients (deno task db:generate).Storage schema fix (surfaced by Prisma regen)
The Neon migration
20260413000000_remove_clerk_fieldshad already dropped thetoken_hashcolumn from thesessionstable, but the generated Prisma types were stale andCreateSessionSchema/HyperdriveStorageAdapter.createSession()still referencedtokenHash. Regenerating the client surfaced this mismatch:src/storage/schemas.ts— RemovedtokenHashfromCreateSessionSchema.src/storage/HyperdriveStorageAdapter.ts— RemovedtokenHashfromprisma.session.create()call.src/storage/schemas.test.ts+HyperdriveStorageAdapter.test.ts— Updated tests accordingly.Dead code deletion
worker/services/user-service.ts— Deleted entirely. ContainedClerkUserData,upsertUserFromClerk,deleteUserByClerkId,findUserByClerkId,updateUserTier— all Clerk-only, never imported in production routing.worker/services/user-service.test.ts— Deleted (tested only the above dead code).Worker cleanup
worker/handlers/admin-handlers.ts— Removedclerk_user_idbackward-compat fallback from the role-assignments list query param (?user_id=is the only accepted param now).admin-analytics-events.ts,admin-logger.ts,admin-audit-service.ts,admin-feature-flag-service.ts,admin-config-service.ts,feature-flag-service.ts.Config
.dev.vars.example— Removed the entire Clerk section:CLERK_PUBLISHABLE_KEY,CLERK_JWKS_URL,CLERK_SECRET_KEY,CLERK_WEBHOOK_SECRET,DISABLE_CLERK_FALLBACK,DISABLE_CLERK_WEBHOOKS.Frontend
admin/api-keys/api-keys.component.ts— RemovedclerkUserIdfrom theAdminApiKeyinterface,displayedColumns, filter logic, table column definition, and detail panel (the field was never returned by the worker API). Updated search label/placeholder from "Search by prefix or owner" → "Search by prefix or name" to accurately reflect the active filter fields (keyPrefix,name).admin/api-keys/api-keys.component.spec.ts— RemovedclerkUserIdfrom interface, factory, fixtures, and the stale'filters by clerkUserId substring'test.admin/roles/roles.component.ts— Changed<mat-label>Clerk User ID</mat-label>→<mat-label>User ID</mat-label>.admin/roles/roles.component.spec.ts— Replaced'clerk-abc','clerk-xyz','clerk-del'test fixture strings with neutral'user-abc','user-xyz','user-del'.admin.guard.ts,app.routes.server.ts,api-key.service.ts,agent-rpc.service.ts,agent.models.ts,webhooks.component.ts,app.config.ts,components/api-keys/api-keys.component.spec.ts.src/ library
IDiagnosticsProvider.ts,CliApp.deno.ts,ArgumentParser.ts,configuration/schemas.ts.Scripts / Postman
scripts/diag-full.ts— Removed the/api/clerk-configdiagnostic probe (endpoint no longer exists).scripts/generate-postman-collection.ts— RenamedclerkToken→bearerTokencollection variable.postman/environments/adblock-compiler.environment.yaml+adblock-compiler-local.environment.yaml— RenamedclerkJwt→bearerToken; removedclerkPublishableKeyentries.OpenAPI / generated API specs
docs/api/openapi.yaml— Removed/api/webhooks/clerkpath block,ClerkJWTsecurity scheme, updatedenum: [local-jwt, clerk]→[local-jwt, better-auth], updated endpoint descriptions.docs/api/cloudflare-schema.yamlanddocs/postman/postman-collection.json— Regenerated viadeno task schema:generate.CI fix
.github/workflows/neon-branch-create.yml— Replacedpnpm/action-setup@v6.0.0(which causedERR_PNPM_BROKEN_LOCKFILEin the Neon Branch: Create workflow) with the./.github/actions/setup-pnpm-nodecomposite action — the same SHA-pinnedpnpm/action-setup@fc06bc1... # v4used by all other CI jobs. Also upgraded the Node.js version from 20 → 22 to match the rest of CI.Testing
deno task preflightexits 0 (fmt, lint, type-check, openapi:validate, schema:generate, check:drift all pass).deno task test— 1407 passed, 0 failed. Parallel validation (Code Review + CodeQL) — no issues found.Zero Trust Architecture Checklist
Worker / Backend
*) on write/authenticated endpoints[vars]) — Clerk secret bindings removed from.dev.vars.example.prepare().bind()(no string interpolation)Frontend / Angular
CanActivateFnauth guardslocalStorage) — N/A; Clerk SDK fully removedAPI Shield / Vulnerability Scanner
operationIdinopenapi.yaml/{id}path parameters) include asecurity:annotationWHERE user_id = ?) — not just by ID404(not403) to avoid leaking resource existencecloudflare-schema.yamlregenerated ifopenapi.yamlchanged (deno task schema:cloudflare)