@krak-stack/auth 0.2.23 → 0.2.24

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @krak-stack/auth
2
2
 
3
+ ## 0.2.24
4
+
5
+ ### Patch Changes
6
+
7
+ - Improve the sign-in flow by moving email-code/password switching into the alternative options below the primary action. Replace the inline email-change link with a Back control so users can return to the initial screen and choose Google. Persist successful code-send timestamps in local storage to preserve the resend cooldown across method switches and reloads, and reuse unexpired codes instead of sending duplicate emails when switching back to email code.
8
+
3
9
  ## 0.2.23
4
10
 
5
11
  ### Patch Changes
package/README.md CHANGED
@@ -57,6 +57,34 @@ const program = Effect.gen(function* () {
57
57
 
58
58
  Use `AuthMiddleware.layer()` to provide request headers and configuration in an Effect HttpApi application. See the [middleware guide](https://auth.krakstack.net/en/docs/middleware).
59
59
 
60
+ `AuthMiddleware` also annotates request logs and spans with verified user,
61
+ organization, and actor IDs using its existing session lookup. Missing sessions
62
+ are anonymous; auth service failures are not silently treated as anonymous.
63
+ `ActorRequired` remains responsible for project authorization and `CurrentActor`.
64
+
65
+ For plain `HttpRouter` routes, use the same authentication through
66
+ `AuthMiddleware.routerLayer()`. For example, browser Events ingestion can inherit
67
+ verified identity without an `Events.layer({ identity })` callback:
68
+
69
+ ```ts
70
+ import { AuthMiddleware } from "@krak-stack/auth/server";
71
+ import { HttpApiOtlp } from "@krak-stack/registry/opentelemetry/api";
72
+ import { Events } from "@krak-stack/registry/events";
73
+ import { Layer } from "effect";
74
+
75
+ const telemetry = HttpApiOtlp.layer.pipe(
76
+ Layer.provide(AuthMiddleware.routerLayer({ paths: ["/api/otel/v1/logs"] })),
77
+ Layer.provide(Events.processorLayer),
78
+ Layer.provide(eventsLayer),
79
+ );
80
+ ```
81
+
82
+ Here `eventsLayer` is the configured Events layer, with SQL provided when
83
+ persistence is needed. `paths` limits auth lookup to the listed URL pathnames;
84
+ without it, the middleware covers every route it is provided to. The router
85
+ adapter uses the same auth configuration and organization-impersonation policy
86
+ as `AuthMiddleware.layer()`. It does not grant permissions or provide `CurrentActor`.
87
+
60
88
  ## React Components
61
89
 
62
90
  The component bundle uses the optional peer dependencies declared in `package.json` and Krakstack/shadcn UI primitives from `@krak-stack/registry`. Install the component peers used by your application; server-only consumers only need `effect`.
@@ -92,4 +120,30 @@ See [React components and CSS](https://auth.krakstack.net/en/docs/components) fo
92
120
 
93
121
  Define project permissions with `defineProjectAccess`, resolve actors with `ActorRequired`, and enforce backend policies with `withPolicy`. Frontend permission helpers control presentation only.
94
122
 
123
+ `AuthMiddleware` annotates the current span, child spans and handler logs with verified attribution:
124
+
125
+ | Attribute | User session | User-owned API key | Organization-owned API key |
126
+ | ---------------------- | ---------------------- | ---------------------- | -------------------------- |
127
+ | `app.actor.type` | `user` | `api_key` | `api_key` |
128
+ | `app.actor.id` | User ID | API-key ID | API-key ID |
129
+ | `app.actor.owner.type` | Omitted | `user` | `organization` |
130
+ | `app.actor.owner.id` | Omitted | Owner user ID | Owner organization ID |
131
+ | `user.id` | User ID | Owner user ID | Omitted |
132
+ | `organization.id` | Active organization ID | Active organization ID | Owner organization ID |
133
+
134
+ The `app.actor.*` fields and existing `organization.id` are application conventions, not standard OTel actor attributes. The public actor model still uses `type: "apiKey"`; `api_key` is its telemetry representation. Only identifiers are emitted, never API-key values or session tokens. Consumers such as transactional audit recording can inherit these log annotations without depending on the auth SDK. MCP and AI execution context belongs to the respective integration layers and does not replace the authenticated actor.
135
+
136
+ Auth-owned user, organization and actor annotations replace the inherited set,
137
+ preventing stale user/API-key owner attribution. Unrelated request, MCP and agent
138
+ context is preserved, and scoped log/child-span context is restored afterward.
139
+ Stale fields on an already-created current span are cleared to empty strings
140
+ because the tracer interface has no attribute-removal method; handler logs and
141
+ new child spans omit those fields entirely.
142
+
143
+ `ActorRequired` does not construct or rewrite attribution. It resolves the project
144
+ actor, enforces actor constraints, and provides `CurrentActor`, preserving the
145
+ annotations established by `AuthMiddleware`. When supplying `AuthService` directly
146
+ without `AuthMiddleware`, authorization still works, but no auth attribution is
147
+ added automatically.
148
+
95
149
  See the [RBAC guide](https://auth.krakstack.net/en/docs/rbac).