feat(web): Add auth account data foundation#5
Conversation
Implement Auth.js credentials auth, Drizzle PostgreSQL migrations, account ownership helpers, and focused auth/account tests. - Add local credentials registration and sign-in support with scrypt password hashing - Create Drizzle schema and migration for Auth.js, accounts, sources, chunks, trace refs, and pgvector - Add fail-closed account scope helpers and update docs/env setup Validation: - pnpm --filter @ancora/web lint - pnpm --filter @ancora/web typecheck - pnpm --filter @ancora/web test - pnpm --filter @ancora/web exec drizzle-kit check --config drizzle.config.ts - docker compose -f docker/docker-compose.yml config - pnpm repo:test:fast - pnpm repo:test:task - pnpm repo:test:context
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 8b6d4e2b62
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
Persist active account selection for credentials users and constrain source chunks to their source account at the schema boundary. Validation: - PATH=/opt/homebrew/bin:/Users/brayanbedritchuk/.codex/tmp/arg0/codex-arg03j9X98:/usr/bin:/bin:/usr/sbin:/sbin:/Applications/Codex.app/Contents/Resources pnpm --filter @ancora/web lint - /opt/homebrew/bin/pnpm --filter @ancora/web typecheck - /opt/homebrew/bin/pnpm --filter @ancora/web test - /opt/homebrew/bin/pnpm --filter @ancora/web exec drizzle-kit check --config drizzle.config.ts - PATH=/opt/homebrew/bin:/usr/local/bin:/Users/brayanbedritchuk/.codex/tmp/arg0/codex-arg03j9X98:/usr/bin:/bin:/usr/sbin:/sbin:/Applications/Codex.app/Contents/Resources pnpm repo:test:fast
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 2d088169ac
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| sourceId: text("source_id").references(() => sources.id, { onDelete: "set null" }), | ||
| sourceChunkId: text("source_chunk_id").references(() => sourceChunks.id, { | ||
| onDelete: "set null", |
There was a problem hiding this comment.
Enforce account-scoped FKs for trace source references
llm_trace_refs stores an account_id but its source_id and source_chunk_id columns only reference global IDs, so an insert can point a trace row in account A at a source or chunk owned by account B while still satisfying both foreign keys. That breaks tenant isolation at the data layer and can leak cross-account lineage whenever account-scoped trace queries later join to sources/chunks; make these references account-scoped (for example with composite FKs including account_id) to enforce consistency.
Useful? React with 👍 / 👎.
Summary
Changes
active_account_idfor credentials users and verify that the selected account has a membership before returning session scope.vector(1536), and LLM trace references.(account_id, source_id)foreign key tosources(account_id, id).Diagram
Testing
pnpm --filter @ancora/web lintpnpm --filter @ancora/web typecheckpnpm --filter @ancora/web testpnpm --filter @ancora/web exec drizzle-kit check --config drizzle.config.tsdocker compose -f docker/docker-compose.yml configpnpm repo:test:fastpnpm repo:test:taskpnpm repo:test:contextrg -n "auth|account|session|cross-account|migration|Implemented|Planned" README.md docsNotes