Skip to content

refactor: route team bootstrap through dashboard admin API#298

Merged
ben-fornefeld merged 11 commits intomainfrom
refactor/user-team-setup-via-dashboard-api
Apr 17, 2026
Merged

refactor: route team bootstrap through dashboard admin API#298
ben-fornefeld merged 11 commits intomainfrom
refactor/user-team-setup-via-dashboard-api

Conversation

@ben-fornefeld
Copy link
Copy Markdown
Member

Summary

  • route dashboard team resolution through the dashboard API and pass the authenticated user id into resolveUserTeam
  • switch user bootstrapping to the new /admin/users/{userId}/bootstrap contract and update generated API types
  • split bootstrap logic into a dedicated admin users repository and keep user team reads scoped to the access token-backed teams repository

Bootstrap users through the dashboard-api callback and fallback resolver paths, and use the teams repository for create-team instead of direct API calls.

Made-with: Cursor
Copilot AI review requested due to automatic review settings April 16, 2026 20:53
@vercel
Copy link
Copy Markdown

vercel bot commented Apr 16, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
web Ready Ready Preview, Comment Apr 16, 2026 11:47pm
web-juliett Ready Ready Preview, Comment Apr 16, 2026 11:47pm

Request Review

@cursor
Copy link
Copy Markdown

cursor bot commented Apr 16, 2026

PR Summary

Medium Risk
Touches sign-in callback and team resolution flow, adding optional admin-token bootstrapping and new API contracts; misconfiguration or contract mismatches could affect first-login onboarding/team selection.

Overview
Routes team creation and user bootstrapping through the Dashboard API contracts. The OpenAPI spec/types add POST /teams, POST /admin/users/{userId}/bootstrap (protected by new X-Admin-Token auth), and extend UserTeam with createdAt.

Updates server flows to pass the authenticated userId into resolveUserTeam, and when ENABLE_USER_BOOTSTRAP is set, attempts to bootstrap a personal team via a new AdminUsersRepository during auth callback and when a user has zero teams. Team creation is refactored to use createTeamsRepository.createTeam, and team-scoped repository methods now return a structured error when teamId is missing instead of throwing; tests are added/updated accordingly.

Reviewed by Cursor Bugbot for commit 5e079ff. Bugbot is set up for automated code reviews on this repo. Configure here.

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 617b36d840

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread src/core/modules/teams/teams-repository.server.ts
Comment thread src/app/api/auth/callback/route.ts Outdated
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Routes team bootstrap and team creation through the Dashboard Admin/API contracts, ensuring user/team resolution happens via the dashboard API with explicit user context.

Changes:

  • Added dashboard admin-token support (env + header helpers) and introduced an AdminUsersRepository for /admin/users/{userId}/bootstrap.
  • Updated resolveUserTeam to accept userId and bootstrap the user when no teams are found.
  • Moved team creation to TeamsRepository.createTeam() and updated OpenAPI spec + generated dashboard API types accordingly.

Reviewed changes

Copilot reviewed 15 out of 15 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/lib/env.ts Adds required DASHBOARD_API_ADMIN_TOKEN to server env schema.
src/configs/api.ts Introduces X-Admin-Token header constant + helper.
src/core/shared/contracts/dashboard-api.types.ts Updates generated types to include /teams POST and /admin/users/{userId}/bootstrap plus new/updated schemas.
src/core/modules/users/admin-repository.server.ts New server-only admin users repository to call bootstrap endpoint.
src/core/server/functions/team/resolve-user-team.ts Adds userId param and bootstraps user when team list is empty.
src/core/modules/teams/teams-repository.server.ts Adds createTeam() and makes teamId optional in scope with a runtime guard for team-scoped ops.
src/core/modules/teams/user-teams-repository.server.ts Removes unused secondsInDay import.
src/core/server/actions/team-actions.ts Switches team creation to repository-backed dashboard API call.
src/app/api/auth/callback/route.ts Bootstraps user after auth callback via admin repository.
src/app/dashboard/route.ts Passes userId into resolveUserTeam.
src/app/dashboard/account/route.ts Passes userId into resolveUserTeam.
src/app/sbx/new/route.ts Passes userId into resolveUserTeam.
src/test/integration/resolve-user-team.test.ts Updates tests for new resolveUserTeam(userId, accessToken) signature and bootstrap behavior.
src/test/integration/dashboard-route.test.ts Updates expectation for resolveUserTeam call signature.
spec/openapi.dashboard-api.yaml Adds AdminTokenAuth scheme, /teams POST, and /admin/users/{userId}/bootstrap path; updates UserTeam.createdAt.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/core/modules/teams/teams-repository.server.ts Outdated
Comment thread src/core/modules/users/admin-repository.server.ts Outdated
Comment thread src/app/api/auth/callback/route.ts
Comment thread src/app/api/auth/callback/route.ts
Copy link
Copy Markdown

@cursor cursor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 2 potential issues.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 174a35c. Configure here.

Comment thread src/app/api/auth/callback/route.ts Outdated
Comment thread src/app/api/auth/callback/route.ts
@ben-fornefeld ben-fornefeld changed the title Route team bootstrap through dashboard admin API fix: route team bootstrap through dashboard admin API Apr 16, 2026
@ben-fornefeld ben-fornefeld changed the title fix: route team bootstrap through dashboard admin API refactor: route team bootstrap through dashboard admin API Apr 16, 2026
Copy link
Copy Markdown
Contributor

@dobrac dobrac left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! one question left

)
}

if (ENABLE_USER_BOOTSTRAP) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do we need this under a flag?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

only temporary for the migration period

@ben-fornefeld ben-fornefeld merged commit fc23c8a into main Apr 17, 2026
11 checks passed
@ben-fornefeld ben-fornefeld deleted the refactor/user-team-setup-via-dashboard-api branch April 17, 2026 07:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants