
LOG Error creating driver [AppwriteException: Missing "execute" permission for role "users". Only "["any","guests"]" scopes are allowed and "["users"]" was given.]
LOG Error creating driver [Error: AppwriteException: Missing "execute" permission for role "users". Only "["any","guests"]" scopes are allowed and "["users"]" was given.]
try {
const newuser = await account.create(
ID.unique(),
user.email,
user.password,
name
);
const res = await functions.createExecution(
CREATE_LABEL_FUNCTION_ID,
JSON.stringify(`{userId: ${newuser.$id}, label: "driver"}`),
true,
"/",
ExecutionMethod.POST
);
return { user: newuser };
} catch (error: any) {
console.log("Error creating driver", error);
throw new Error(error);
}

Hey.
When creating an account, you are not logged in. You need to login first and then use the function

Or, a better way, is to use events in the function settings.

oh great, please how do use event to detect the type of user that register, and set the label for that user. My app two type of users (users,driver)

You could use something like users.*.create. Check the functions settings tab.

In your function you can then use
const document = req.body;
, where document will contain the data of your user.
Just use log(document) and you can see what it contains. It should contain the user document.

ok, this is good, but the user create function
const newuser = await account.create(
ID.unique(),
user.email,
user.password,
name
);
does not have any field where I could add a custom tag(or something), so that I can check for it const document = req.body;
and then add my desired label to the user

In your function you need to update the user to add the label, you can get the user id from document.userId.

ok, i think i get how to go about it now
on user creation i will set the name to user type (driver or user) then update the label based on the name
then whenever the user logs in on my app, i will check there name and if it is still driver or user, i will update it with there real name that i already save on a profile document while creating their account

@faye this is my final solution, though am yet to test it
export default async ({ req, res, log, error }) => {
try {
const client = new Client()
.setEndpoint(process.env.APPWRITE_FUNCTION_API_ENDPOINT)
.setProject(process.env.APPWRITE_FUNCTION_PROJECT_ID)
.setKey(req.headers['x-appwrite-key'] ?? '');
// console.log(req.headers['x-appwrite-key']);
const users = new Users(client);
const { name, userId } = JSON.parse(req.body);
const label = name.split('-')[1];
const finalName = name.split('-')[0];
log('req', typeof req.body);
log('userId', userId);
await users.updateLabels(userId, [label]);
await users.updateName(userId, finalName);
return 'User label updated successfully';
} catch (err) {
log('Could not list users: ' + err.message);
error('Could not list users: ' + err.message);
}
};
const name = `${user.firstName} ${user.lastName}-driver`;
try {
const newuser = await account.create(
ID.unique(),
user.email,
user.password,
name
);
// create driver document
await createDriverDoc(user, newuser.$id);
return { user: newuser };
} catch (error: any) {
console.log("Error creating driver", error);
throw new Error(error);
}
Recommended threads
- Sharing cookies
Hi, I’m using Appwrite Cloud, and I have a setup where my Appwrite backend is hosted on a subdomain (e.g., api.example.com), while my frontend (Next.js app) and...
- Custom Domain Issue
i have added a custom domain about 21 hours ago, but till now there is no SSL certificate is active on it. but if i do DNS check via https://dnschecker.org/#C...
- Flutter OAuth2 Google does not return to...
When the flow starts, the browser opens, I select an account, and it keeps showing: """ Page not found The page you're looking for doesn't exist. `general_rout...
