Skip to content

feat(auth): packages/auth on Effect #74

Closed

Description

@allisonmahmood

Problem

Tokens, principals, self-service mint, quota and revocation are spread across packages/db (internal-principals.ts, mint-quota.ts, the Postgres driver) and apps/server/src/app.ts. They become one capability package that implements the auth API group.

Do

  • packages/auth: services for token minting + mint quota, principal lookup by sha256(token), revocation and bearer parsing, one file each per .agents/skills/effect-service-conventions/SKILL.md; failures as Schema.TaggedError with structured fields; row decoding through SqlSchema in one module.
  • Migrations 1–2 rewritten as the baseline for accounts, api_tokens, token_mints (integer ids in the global sequence), registered in the sql migrator's record.
  • Implements the auth HttpApi group from packages/api with HttpApiBuilder.group and the server-side bearer middleware (Authorization.of({ bearer }) providing the current principal). sql.withTransaction where today's code holds a manual transaction for minting.
  • Emits its analytics events through packages/analytics; mint rate limiting through packages/limits.
  • Interim: Fastify serves the group's routes through the seam (the handler layer is called via runPromise); the serving ticket replaces the seam with HttpApiBuilder.layer.
  • Tests: it.layer on a migrated database, HttpApiTest.groups(PatchyApi, ["auth"]) for the routes (good/bad tokens as two HttpApiMiddleware.layerClient layers), the 401 body asserted; split the auth cases out of app.postgres.test.ts.
  • Move token / principal / mint / quota / revocation terms from apps/server/CONTEXT.md to packages/auth/CONTEXT.md; packages/auth/docs/adr/ if a decision meets the tests. Promote the language-service warnings to error for the package.

Done when

No auth logic remains in packages/db or app.ts; the auth group passes HttpApiTest; the packed-CLI e2e still passes against the Fastify server.

Decisions implemented

Spec §1, §2, §3, §6, §7; Package decomposition by capability.


Filed from the Effect v4 port spec (#68) by the map task Write the port spec and file the build tickets.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:serverready-for-agent

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions