Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export default function PageClient() {

setIsTransferring(true);
try {
await project.transfer(user, selectedTeamId);
await user.transferProject(project.id, selectedTeamId);

// Reload the page to reflect changes
// we don't actually need this, but it's a nicer UX as it clearly indicates to the user that a "big" change was made
Expand Down
17 changes: 0 additions & 17 deletions packages/stack-shared/src/interface/admin-interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -317,23 +317,6 @@ export class StackAdminInterface extends StackServerInterface {
);
}

async transferProject(session: InternalSession, newTeamId: string): Promise<void> {
await this.sendAdminRequest(
"/internal/projects/transfer",
{
method: "POST",
headers: {
"content-type": "application/json",
},
body: JSON.stringify({
project_id: this.options.projectId,
new_team_id: newTeamId,
}),
},
session,
);
}

async getMetrics(includeAnonymous: boolean = false): Promise<any> {
const params = new URLSearchParams();
if (includeAnonymous) {
Expand Down
20 changes: 20 additions & 0 deletions packages/stack-shared/src/interface/client-interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1797,5 +1797,25 @@ export class StackClientInterface {
const { url } = await response.json() as { url: string };
return url;
}

async transferProject(internalProjectSession: InternalSession, projectIdToTransfer: string, newTeamId: string): Promise<void> {
if (this.options.projectId !== "internal") {
throw new StackAssertionError("StackClientInterface.transferProject() is only available for internal projects (please specify the project ID in the constructor)");
}
await this.sendClientRequest(
"/internal/projects/transfer",
{
method: "POST",
headers: {
"content-type": "application/json",
},
body: JSON.stringify({
project_id: projectIdToTransfer,
new_team_id: newTeamId,
}),
},
internalProjectSession,
);
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { StackAssertionError, throwErr } from "@stackframe/stack-shared/dist/uti
import { pick } from "@stackframe/stack-shared/dist/utils/objects";
import { Result } from "@stackframe/stack-shared/dist/utils/results";
import { useMemo } from "react"; // THIS_LINE_PLATFORM react-like
import { AdminSentEmail, CurrentUser } from "../..";
import { AdminSentEmail } from "../..";
import { EmailConfig, stackAppInternalsSymbol } from "../../common";
import { AdminEmailTemplate } from "../../email-templates";
import { InternalApiKey, InternalApiKeyBase, InternalApiKeyBaseCrudRead, InternalApiKeyCreateOptions, InternalApiKeyFirstView, internalApiKeyCreateOptionsToCrud } from "../../internal-api-keys";
Expand Down Expand Up @@ -196,10 +196,6 @@ export class _StackAdminAppImplIncomplete<HasTokenStore extends boolean, Project
async delete() {
await app._interface.deleteProject();
},
async transfer(user: CurrentUser, newTeamId: string) {
await app._interface.transferProject(user._internalSession, newTeamId);
await onRefresh();
},
async getProductionModeErrors() {
return getProductionModeErrors(data);
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1247,6 +1247,10 @@ export class _StackClientAppImplIncomplete<HasTokenStore extends boolean, Projec
createProject(newProject: AdminProjectUpdateOptions & { displayName: string, teamId: string }) {
return app._createProject(session, newProject);
},
async transferProject(projectIdToTransfer: string, newTeamId: string): Promise<void> {
await app._interface.transferProject(session, projectIdToTransfer, newTeamId);
await app._refreshProject();
Copy link
Contributor

Choose a reason for hiding this comment

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

logic: Only refreshes current project cache, but transferring a project might affect owned projects list and should refresh _ownedProjectsCache as well

Suggested change
await app._refreshProject();
await app._refreshProject();
await app._refreshOwnedProjects(session);
Prompt To Fix With AI
This is a comment left during a code review.
Path: packages/template/src/lib/stack-app/apps/implementations/client-app-impl.ts
Line: 1252:1252

Comment:
**logic:** Only refreshes current project cache, but transferring a project might affect owned projects list and should refresh `_ownedProjectsCache` as well

```suggestion
        await app._refreshProject();
        await app._refreshOwnedProjects(session);
```

How can I resolve this? If you propose a fix, please make it concise.

},
listOwnedProjects() {
return app._listOwnedProjects(session);
},
Expand Down
1 change: 1 addition & 0 deletions packages/template/src/lib/stack-app/users/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,7 @@ export type UserExtra = {
export type InternalUserExtra =
& {
createProject(newProject: AdminProjectCreateOptions): Promise<AdminOwnedProject>,
transferProject(projectIdToTransfer: string, newTeamId: string): Promise<void>,
}
& AsyncStoreProperty<"ownedProjects", [], AdminOwnedProject[], true>

Expand Down
Loading