Skip to content

Commit e5918aa

Browse files
authored
invite users api (#47)
1 parent 84de8a5 commit e5918aa

2 files changed

Lines changed: 30 additions & 0 deletions

File tree

src/client.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { getAccessToken } from "./utils/auth-utils.js";
88
import { createFunctionsModule } from "./modules/functions.js";
99
import { createAgentsModule } from "./modules/agents.js";
1010
import { createAppLogsModule } from "./modules/app-logs.js";
11+
import { createUsersModule } from "./modules/users.js";
1112
import { RoomsSocket, RoomsSocketConfig } from "./utils/socket-utils.js";
1213

1314
export type CreateClientOptions = {
@@ -119,6 +120,7 @@ export function createClient(config: {
119120
token,
120121
}),
121122
appLogs: createAppLogsModule(axiosClient, appId),
123+
users: createUsersModule(axiosClient, appId),
122124
cleanup: () => {
123125
socket.disconnect();
124126
},

src/modules/users.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import { AxiosInstance } from "axios";
2+
3+
/**
4+
* Creates the users module for the Base44 SDK
5+
* @param {AxiosInstance} axios - Axios instance
6+
* @param {string} appId - Application ID
7+
* @returns {Object} Users module
8+
*/
9+
export function createUsersModule(axios: AxiosInstance, appId: string) {
10+
return {
11+
/**
12+
* Invite a user to the application
13+
* @param {string} user_email - User's email address
14+
* @param {'user'|'admin'} role - User's role (user or admin)
15+
* @returns {Promise<any>}
16+
*/
17+
async inviteUser(user_email: string, role: "user" | "admin"): Promise<any> {
18+
if (role !== "user" && role !== "admin") {
19+
throw new Error(
20+
`Invalid role: "${role}". Role must be either "user" or "admin".`
21+
);
22+
}
23+
24+
const response = await axios.post(`/apps/${appId}/runtime/users/invite-user`, { user_email, role });
25+
return response;
26+
},
27+
};
28+
}

0 commit comments

Comments
 (0)