Rank 2: Process
Expectation:
When I pass a user session ID to the cloud function via a REST API call, and I create a team, the team should be assigned to that user.
If I request a list of teams, the cloud function should return the team list for that specific user.
// "aw" stands for Appwrite. Get the Appwrite API key and user session ID from HTTP request headers.
String awKey = context.req.headers['x-appwrite-key'] ?? '';
String awUserSessionId = context.req.headers['x-appwrite-user-session-id'] ?? '';
context.log("Appwrite Key: $awKey");
context.log("Appwrite User Session ID: $awUserSessionId");
// If either the key or session ID is present in the request, update the client configuration.
if (awKey.isNotEmpty || awUserSessionId.isNotEmpty) {
client.setKey(awKey);
client.setSession(awUserSessionId);
}
// "aw" stands for AppWrite
awDatabases = Databases(client);
awTeams = Teams(client);
awUsers = Users(client);
awAccount = Account(client);
// Get the user account based on the session ID.
User account = await awAccount!.get();
// Create a team and associate it with the authenticated user.
Team? team = await awTeams?.create(
teamId: dbTeamId,
name: pbMessage.friendlyName,
);