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
- Cant configure email templates
i configure it on the console, and when i send the OTP, it sends with appwrite's email (instead of custom smtp) and with the branding, but i have the Pro (educa...
- Need help with createExecution function
Hi, Need some help understanding createExecution. When requesting function execution via createExecution, the function handler arguments are incorrect and rese...
- Need Help with Google OAuth2 in Expo usi...
I'm learning React Native with Expo and trying to set up Google OAuth2 with Appwrite. I couldn't find any good docs or tutorials for this and my own attempt did...