mirror of
https://github.com/stack-auth/stack.git
synced 2026-06-04 21:04:37 +08:00
Auto select team on creation (#567)
Some checks failed
all-good: Did all the other checks pass? / all-good (push) Has been cancelled
Ensure Prisma migrations are in sync with the schema / check_prisma_migrations (22.x) (push) Has been cancelled
Docker Build and Push / Docker Build and Push Server (push) Has been cancelled
Docker Test / docker (push) Has been cancelled
Runs E2E API Tests / build (22.x) (push) Has been cancelled
Lint & build / lint_and_build (latest) (push) Has been cancelled
Preview Docs / run (push) Has been cancelled
Dev Environment Test / restart-dev-and-test (push) Has been cancelled
Run setup tests / setup-tests (push) Has been cancelled
TOC Generator / TOC Generator (push) Has been cancelled
Some checks failed
all-good: Did all the other checks pass? / all-good (push) Has been cancelled
Ensure Prisma migrations are in sync with the schema / check_prisma_migrations (22.x) (push) Has been cancelled
Docker Build and Push / Docker Build and Push Server (push) Has been cancelled
Docker Test / docker (push) Has been cancelled
Runs E2E API Tests / build (22.x) (push) Has been cancelled
Lint & build / lint_and_build (latest) (push) Has been cancelled
Preview Docs / run (push) Has been cancelled
Dev Environment Test / restart-dev-and-test (push) Has been cancelled
Run setup tests / setup-tests (push) Has been cancelled
TOC Generator / TOC Generator (push) Has been cancelled
- Updated usersCrudHandlers to create a team upon user sign-up and set
the team member's selection status.
- Modified client and server app implementations to ensure the selected
team ID is updated after team creation.
<!--
Make sure you've read the CONTRIBUTING.md guidelines:
https://github.com/stack-auth/stack-auth/blob/dev/CONTRIBUTING.md
-->
<!-- ELLIPSIS_HIDDEN -->
----
> [!IMPORTANT]
> Automatically select a team upon user creation by updating backend and
client/server logic to set the selected team ID after team creation.
>
> - **Backend**:
> - In `usersCrudHandlers` in `crud.tsx`, create a team on user sign-up
and set `isSelected` to `BooleanTrue.TRUE` for the team member.
> - **Client**:
> - In `_StackClientAppImplIncomplete` in `client-app-impl.ts`, update
`createTeam()` to set `selectedTeamId` after team creation.
> - **Server**:
> - In `_StackServerAppImplIncomplete` in `server-app-impl.ts`, update
`createTeam()` to set `selectedTeamId` after team creation.
>
> <sup>This description was created by </sup>[<img alt="Ellipsis"
src="https://img.shields.io/badge/Ellipsis-blue?color=175173">](https://www.ellipsis.dev?ref=stack-auth%2Fstack-auth&utm_source=github&utm_medium=referral)<sup>
for 0321b6c724. It will automatically
update as commits are pushed.</sup>
<!-- ELLIPSIS_HIDDEN -->
This commit is contained in:
parent
21a34bcd34
commit
a0e32c0fbd
@ -728,7 +728,7 @@ export const usersCrudHandlers = createLazyProxy(() => createCrudHandlers(usersC
|
||||
});
|
||||
|
||||
if (auth.tenancy.config.create_team_on_sign_up) {
|
||||
await teamsCrudHandlers.adminCreate({
|
||||
const team = await teamsCrudHandlers.adminCreate({
|
||||
data: {
|
||||
display_name: data.display_name ?
|
||||
`${data.display_name}'s Team` :
|
||||
@ -740,6 +740,19 @@ export const usersCrudHandlers = createLazyProxy(() => createCrudHandlers(usersC
|
||||
tenancy: auth.tenancy,
|
||||
user: result,
|
||||
});
|
||||
|
||||
await prismaClient.teamMember.update({
|
||||
where: {
|
||||
tenancyId_projectUserId_teamId: {
|
||||
tenancyId: auth.tenancy.id,
|
||||
projectUserId: result.id,
|
||||
teamId: team.id,
|
||||
},
|
||||
},
|
||||
data: {
|
||||
isSelected: BooleanTrue.TRUE,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
runAsynchronouslyAndWaitUntil(sendUserCreatedWebhook({
|
||||
|
||||
@ -856,6 +856,7 @@ export class _StackClientAppImplIncomplete<HasTokenStore extends boolean, Projec
|
||||
async createTeam(data: TeamCreateOptions) {
|
||||
const crud = await app._interface.createClientTeam(teamCreateOptionsToCrud(data, 'me'), session);
|
||||
await app._currentUserTeamsCache.refresh([session]);
|
||||
await this.update({ selectedTeamId: crud.id });
|
||||
return app._clientTeamFromCrud(crud, session);
|
||||
},
|
||||
async leaveTeam(team: Team) {
|
||||
|
||||
@ -308,6 +308,7 @@ export class _StackServerAppImplIncomplete<HasTokenStore extends boolean, Projec
|
||||
...data,
|
||||
}));
|
||||
await app._serverTeamsCache.refresh([undefined]);
|
||||
await app._updateServerUser(crud.id, { selectedTeamId: team.id });
|
||||
return app._serverTeamFromCrud(team);
|
||||
},
|
||||
leaveTeam: async (team: Team) => {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user