Skip to content

apps dashboard session and api

bondiano edited this page Nov 12, 2026 · 1 revision

Session and API client

Active contributors: Vassiliy Kuzenkov

Session owns the signed-in caller and the controls that depend on repository roles. Api supplies generated HTTP types and a cookie-based, same-origin transport; TanStack Query keeps fetched state outside individual pages.

Scope: web/src/modules/Session/ and web/src/modules/Api/ have 8 source files, 3 test files, a 37.5% test/source file ratio and 1 unique nonbot author on origin/main. Counts exclude the generated API declaration and adjacent app/page code; see the counting method.

Sign-in and session lifecycle

web/src/pages/login.vue supports two entry paths:

Entry Browser behavior Identity after sign-in
GitHub OAuth useSignIns() reads /auth/github; each returned login URL is a full-page link A GitHub user with repository grants returned by /v1/me
API client token signInWithToken() posts to /auth/token with an Authorization header A browser session acting as that configured API client

The requests are implemented in web/src/modules/Session/session.ts. The token is a password-input draft and is cleared after successful exchange; it is not stored as a long-lived browser bearer credential. Subsequent API calls use the session cookie through web/src/modules/Api/client.ts.

The server owns OAuth state, callback validation and session cookies. crates/sych-app/src/server/auth.rs creates an eight-hour HttpOnly, SameSite=Lax session, with Secure enabled for an HTTPS public URL. GitHub's temporary user token stays out of the page. See server authentication and the API contract for backend details.

sessionGuard() skips public routes and otherwise calls ensureQueryData for ['me']. A 401 redirects to /login?next=…; other errors are propagated rather than treated as signed-out. useMe() has a 60-second stale time, but the guard can reuse already-cached data, so navigation is not a fresh permission check. Both behaviors are in web/src/modules/Session/session.ts.

web/src/pages/login.vue accepts a next string only when it starts with / but not //; it defaults to /. The OAuth server also resolves and confines the landing path under /ui/ in crates/sych-app/src/server/auth.rs. The frontend check alone is not the server's redirect-safety boundary.

Sign-out posts /auth/logout, clears the entire QueryClient after success and navigates to login. A failed logout does not pretend that the session ended. The shared query cache also redirects to login on a query's 401 while a page is open, retaining the current route as next, in web/src/app/entry.ts.

Roles and action visibility

web/src/modules/Session/roles.ts orders roles as reader < triage < writer < maintainer. can(me, role, repositoryId) checks that exact repository; canSomewhere(me, role) is suitable only for section navigation. Missing callers and missing grants allow nothing in these helpers.

Capability UI condition Concrete source
Read signed-in pages Session guard; API filters readable repositories web/src/modules/Session/session.ts
Record finding feedback Triage on the finding's repository web/src/pages/findings/[id].vue
Rerun an open/draft change or cancel its active run Writer on that repository web/src/pages/changes/[id].vue, web/src/modules/Operations/ui/JobsTable.vue
Create/revoke waivers, decide suggestions, start playground tries Maintainer on the relevant repository web/src/pages/findings/[id].vue, web/src/modules/Waivers/ui/WaiversTable.vue, web/src/pages/suggestions/index.vue, web/src/pages/changes/[id].vue
Recreate an uncertain publication Writer on the publication's repository web/src/modules/Operations/ui/UnresolvedList.vue
Show Playground/Audit navigation Maintainer somewhere web/src/app/layouts/default.vue
Show Admin navigation Server-returned me.admin web/src/app/layouts/default.vue

GitHub read/triage/write/maintain-or-admin map to those four roles in crates/sych-app/src/server/caller.rs; unsupported levels grant no role. API-client sessions resolve their current configured scope and role on the server. A GitHub maintainer is not automatically an instance administrator: crates/sych-app/src/server/admin.rs requires a maintainer client with wildcard repository access for its operator view.

These controls are hints, not authorization. The server checks repository scope and rechecks a person's permission with GitHub for mutations; cookie-authenticated mutations must have the configured same origin. A 403 remains visible as a refusal, not a reason for the browser to grant more access. The implementation boundary is crates/sych-app/src/server/caller.rs.

Repository and instance selectors

web/src/modules/Session/ui/RepositorySelect.vue lists only grants from /v1/me. Its “Every repository” option means every repository the caller can read; it writes undefined, not a wildcard authorization grant. Pages convert the textual selection using web/src/common/utilities/toId.ts.

web/src/modules/Session/ui/InstanceSwitch.vue uses the server-returned instances list and its current marker. If no current instance is configured, no selector is rendered. Choosing another instance calls window.location.assign() on its URL plus /ui/, as constructed in web/src/modules/Session/instances.ts. This is a full-page navigation to a separate server with its own sign-in, not an in-place API-origin switch or a transfer of the current session.

Typed API boundary

web/src/modules/Api/client.ts creates openapi-fetch with generated paths types, the current origin and credentials: 'same-origin'. It exports Schemas from generated components for domain modules. web/package.json regenerates web/src/modules/Api/schema.gen.d.ts from schemas/openapi.json with pnpm gen:api; do not hand-edit the generated declaration.

unwrap() returns data for every successful HTTP status, including a bodyless 204. Otherwise it raises ApiError with status, envelope code, message and optional correlation ID; an unstructured refusal falls back to UNKNOWN and the HTTP status text. web/src/modules/Ui/components/ErrorNotice.vue displays the message, not the full envelope. Preserve the status/code fields when extending error handling.

Query and cache semantics

Concern Current behavior Implementation
Keys Domain prefix plus reactive ID/filter refs; changing URL filters changes the query For example web/src/modules/Changes/queries.ts, web/src/modules/Analytics/queries.ts
Pagination Lists start without before; next_before supplies the next page; pages flatten results for Load more web/src/modules/Changes/queries.ts, web/src/modules/Findings/queries.ts, web/src/modules/Admin/queries.ts, web/src/modules/Audit/queries.ts, web/src/modules/Operations/queries.ts
Retries Queries retry network/server failures up to twice; ApiError statuses below 500 do not retry web/src/app/entry.ts
Missing artifacts Runs map 409 to null for result/snapshots; tours map 404 or 409 to null web/src/modules/Runs/queries.ts, web/src/modules/Tours/queries.ts
Dependent reads Disable change ID 0, a findings filter with change ID 0, empty result run ID, or unselected policy/suggestion repository Domain query files under web/src/modules/
Broad refresh Rerun/cancel, feedback, waiver create/revoke and reconcile invalidate all queries except me Corresponding domain query files
Narrow refresh Playground invalidates playground; suggestion decisions invalidate suggestions; tour actions invalidate the current tour web/src/modules/Playground/queries.ts, web/src/modules/Suggestions/queries.ts, web/src/modules/Tours/queries.ts
Caller separation Logout clears all cached queries; instance switching reloads the page web/src/modules/Session/session.ts, web/src/modules/Session/ui/InstanceSwitch.vue

Apart from useMe(), these queries do not set a custom stale time or periodic refetch interval. There is no push subscription or persistent-query-cache setup in web/src/app/entry.ts. A run that is still executing is not guaranteed to update on a timer; use normal refetch/navigation behavior rather than documenting the screen as a live stream.

URL filters are computed through web/src/common/composables/useQueryParam.ts, which preserves other query parameters and uses router replacement rather than creating a browser-history entry for every filter edit.

Idempotent user actions

idempotencyKey() in web/src/modules/Api/client.ts generates a UUID. Preserve the distinction between retrying one request and choosing a new action:

  • Rerun/profile choices, playground tries, feedback, waiver creation and publication reconciliation retain a key for the submitted content/options so a failed submission can be retried. Their forms rotate it when the meaningful input changes; feedback, waiver and reconcile use trimmed request content. See web/src/modules/Changes/ui/RerunForm.vue, web/src/modules/Playground/ui/TryForm.vue, web/src/modules/Findings/ui/FeedbackForm.vue, web/src/modules/Waivers/ui/WaiverForm.vue and web/src/modules/Operations/ui/ReconcileForm.vue.
  • Cancel, revoke and suggestion decisions generate keys per click because repeating the same operation does not change the intended final state. Tour reveal, finish and ask actions also generate a fresh key per action in web/src/modules/Tours/queries.ts.
  • No global mutation retry policy is configured in web/src/app/entry.ts. The forms surface failures and allow an explicit resubmission.

Key source files

File Responsibility
web/src/modules/Session/session.ts Caller queries, guard, token exchange and logout
web/src/modules/Session/roles.ts Ordered repository-role checks
web/src/modules/Session/instances.ts Current-instance lookup and dashboard URLs
web/src/modules/Session/ui/InstanceSwitch.vue Cross-server navigation
web/src/modules/Session/ui/RepositorySelect.vue Readable repository selection
web/src/modules/Api/client.ts Generated client wrapper, errors and UUIDs
web/src/modules/Api/__tests__/client.spec.ts Success, 204 and refusal-envelope contracts
web/src/modules/Session/__tests__/roles.spec.ts Role inheritance and repository isolation
web/src/modules/Session/__tests__/instances.spec.ts Instance selection and URL construction

Modification entry points

For a new role-sensitive action, use a repository-specific can() check and implement the matching backend permission before exposing the control. For a new endpoint, update the API, regenerate types and add the domain query through its public module entry.

When changing session/query behavior, check both web/src/modules/Session/session.ts and web/src/app/entry.ts, including logout cache isolation and query 401 redirects. Extend the focused contracts above and the server authentication tests described in Frontend development.

Clone this wiki locally