Plumb me.external_data through session enrichment to useUser#21
Draft
drewda wants to merge 1 commit into
Draft
Conversation
Adds an opaque `external_data` passthrough so consumers can read fields the
backend places on the user context (e.g. tlserver's gatekeeper middleware,
which sets `user.ExternalData["gatekeeper"]` to a JSON-stringified
GatekeeperResponse).
- Session endpoint requests `external_data` alongside id/name/email/roles
from the GraphQL `me` query.
- `enrichUserClaims` includes a new `tlv2_external_data` claim on the
enriched session response (defaults to `{}` when absent).
- `useUser()` exposes `externalData: Record<string, unknown>`.
The map is passed through verbatim — schema is deployment-specific, and
parsing of any deployment-flavored sub-keys (e.g. JSON-stringified
gatekeeper data) lives in the consumer.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds an opaque
external_datapassthrough from the GraphQLmequery to the client-sideuseUser()composable so consumers can read fields the backend places on the user context. Generic plumbing only — no deployment-specific schema is encoded here.The motivating consumer is the Interline Web App Gatekeeper integration:
tlserver's gatekeeper middleware (internal/meters/gatekeeper) calls IWA on every authenticated request, stores the response on the request user viaWithExternalData(), andtransitland-lib'smeresolver returns it asexternal_data["gatekeeper"](a JSON-stringifiedGatekeeperResponse). Today that data is dropped on the floor by tlv2-auth; this PR plumbs it through verbatim. Parsing/typing ofexternal_data.gatekeeper(or any other deployment-flavored sub-key) lives in the consumer (e.g. auseGatekeeper()composable inwww-transit-land-v2).Session endpoint
src/runtime/server/api/auth/session.get.ts— extends the GraphQL query fromme { id name email roles }tome { id name email roles external_data }.Enrichment
src/runtime/util/enrich.ts—enrichUserClaimsaccepts an optionalexternal_datafield onMeDataand writes it totlv2_external_dataon the returned claims (defaults to{}when absent).Composable
src/runtime/composables/useUser.ts—TlUserinterface gains anexternalData: Record<string, unknown>property, populated from thetlv2_external_datasession claim.Tests
src/runtime/util/enrich.spec.ts— adds cases for verbatim passthrough and the empty-default behavior.Test plan
tlv2-authas a Nuxt module, configures its backend'smeresolver to returnexternal_data(e.g.tlserver --auth=gatekeeper), logs in.useUser().externalDatareturns the same shape the backend put on the user (e.g.{ gatekeeper: "<json>", amberflo: { customer_id: "..." } }).external_data,useUser().externalDatais{}.tlv2_external_datafalls through to the default).