mirror of
https://github.com/stack-auth/stack.git
synced 2026-06-13 21:01:21 +08:00
added server user create team (#84)
This commit is contained in:
parent
53c5a87888
commit
29bb31fdbc
@ -932,7 +932,7 @@ export class StackClientInterface {
|
||||
};
|
||||
}
|
||||
|
||||
async createClientTeam(
|
||||
async createTeamForCurrentUser(
|
||||
data: TeamCustomizableJson,
|
||||
session: InternalSession,
|
||||
): Promise<TeamJson> {
|
||||
|
||||
@ -361,4 +361,23 @@ export class StackServerInterface extends StackClientInterface {
|
||||
null,
|
||||
);
|
||||
}
|
||||
|
||||
async createServerTeamForUser(
|
||||
userId: string,
|
||||
data: ServerTeamCustomizableJson,
|
||||
session: InternalSession,
|
||||
): Promise<ServerTeamJson> {
|
||||
const response = await this.sendClientRequest(
|
||||
`/users/${userId}/teams?server=true`,
|
||||
{
|
||||
method: "POST",
|
||||
headers: {
|
||||
"content-type": "application/json",
|
||||
},
|
||||
body: JSON.stringify(data),
|
||||
},
|
||||
session,
|
||||
);
|
||||
return await response.json();
|
||||
}
|
||||
}
|
||||
|
||||
@ -786,7 +786,7 @@ class _StackClientAppImpl<HasTokenStore extends boolean, ProjectId extends strin
|
||||
return useMemo(() => teams.map((json) => app._teamFromJson(json)), [teams]);
|
||||
},
|
||||
async createTeam(data: TeamCustomizableJson) {
|
||||
const teamJson = await app._interface.createClientTeam(data, session);
|
||||
const teamJson = await app._interface.createTeamForCurrentUser(data, session);
|
||||
await app._currentUserTeamsCache.refresh([session]);
|
||||
return app._teamFromJson(teamJson);
|
||||
},
|
||||
@ -1361,8 +1361,10 @@ class _StackServerAppImpl<HasTokenStore extends boolean, ProjectId extends strin
|
||||
useTeams() {
|
||||
return app._useCheckFeatureSupport("useTeams() on ServerUser", {});
|
||||
},
|
||||
createTeam: async () => {
|
||||
throw new Error();
|
||||
createTeam: async (data: ServerTeamCustomizableJson) => {
|
||||
const team = await app._interface.createServerTeamForUser(json.id, data, app._getSession());
|
||||
await app._serverTeamsCache.refresh([]);
|
||||
return app._serverTeamFromJson(team);
|
||||
},
|
||||
async listPermissions(scope: Team, options?: { direct?: boolean }): Promise<ServerPermission[]> {
|
||||
const permissions = await app._serverTeamUserPermissionsCache.getOrWait([scope.id, json.id, 'team', !!options?.direct], "write-only");
|
||||
|
||||
Loading…
Reference in New Issue
Block a user