I try to update the membershiproles of an user when users.*.verification.*.update is triggered. Idk why my function return the error Error adding user to the role maybe there is something wrong with the query when listMemberships is used :
module.exports = async function (req, res) {
const client = new sdk.Client();
const teams = new sdk.Teams(client);
const users = new sdk.Users(client);
if (
!req.variables['APPWRITE_FUNCTION_ENDPOINT'] ||
!req.variables['APPWRITE_FUNCTION_API_KEY']
) {
console.warn("Environment variables are not set. Function cannot use Appwrite SDK.");
} else {
client
.setEndpoint(req.variables['APPWRITE_FUNCTION_ENDPOINT'])
.setProject(req.variables['APPWRITE_FUNCTION_PROJECT_ID'])
.setKey(req.variables['APPWRITE_FUNCTION_API_KEY'])
.setSelfSigned(true);
}
const teamId = req.variables['APPWRITE_FUNCTION_TEAM_ID'];
const token = JSON.parse(req.variables['APPWRITE_FUNCTION_EVENT_DATA']);
const user = await users.get(token.userId);
if (user.emailVerification) {
try {
const members = teams.listMemberships(teamId, [
Query.equal('userId', user.$id)
]);
if (members.total === 1) {
await teams.updateMembershipRoles(teamId, members.memberships[0].$id, ['verified'], 'https://appwrite.nvlab.fr');
res.json({ success: `User ${user.name} added to the Verified Role successfully` });
} else {
throw 'Error looking for a membership user.';
}
} catch (error) {
res.json({ error: 'Error adding user to the role' });
}
}
};
Okay the problem comes from my teamId I guess because even if i do :
console.log(teams.listMemberships(teamId);
No output
It would help if you logged the error and shared it
I think you need to await it
like that : await teams.listMemberships(teamId); ?
When I do console.log(error), ive got an empty {}
Well when i do that :
const membersOld = await teams.listMemberships(teamId);
console.log('Members old', membersOld)
const members = await teams.listMemberships(teamId, [
Query.equal('userId', user.$id)
]);
membersOLD works but not members
well ive no idea why the Query.equal('userId', user.$id) dont work
There is no attribut for Team btw ?
ive no idea why the query dont works
What's the error?
[SOLVED] Update MembershipRoles of a specific user
Recommended threads
- Bulk API limitations in self-hosted serv...
Environment: Appwrite Selfhost SDK: node-appwrite 28.0 Calling `upsertRows` (also applies to `createRows`/`updateRows`/`deleteRows`) with more than 100 rows fa...
- Self Hosted GitHub connection not adding...
After upgrading to 1.9.6 i noticed that i cannot search for new repositories when trying to add new functions. I removed the existing github connection via Set...
- Unable to init function via cli
Hello! I have created a new self hosted instance of appwrite 1.9.6 and have connected to that insatnce with the cli 27.2.0 that was released a few hours ago. Wh...