401 user_unauthorized: The current user is not authorized to perform the requested action.
- 0
- Databases
I am using NextJs with the node-apprite cli. When a user creates an account I need a document to be added to my Users collection. When the code to create the new user's document is called, i get the error stated in the title. This is strange however, since the session is creaed, the user is logged in and the document is created in the database. I've sent a couple of days trying to figure this out. My permissions are essentially set to anyone (any, guest & users) for the sake of experimentation. This is the code to create a user and post to the DB:
const session = await account.createEmailPasswordSession(email, password);
cookies().set("auth-session", session.secret, {
path: "/",
httpOnly: true,
sameSite: "strict",
secure: true,
});
await addUserToDatabase(username, session.userId, email);
...
async function addUserToDatabase(
userName: string,
userId: string,
userEmail: string
) {
const { databases } = await createDatabaseClient();
try {
return await databases.createDocument(
databaseId,
usersCollectionId,
ID.unique(),
{
userName,
userId,
userEmail,
}
);
} catch (error: any) {
if (error.type === "user_unauthorized") {
console.error("Unauthorized to add user to database", error);
} else {
console.error("Error adding user to database", error);
}
}
}
Ok, it would appear the error was being caused by a relation to another collection.
Recommended threads
- API key not having access to database
My api key with read and write access to row and tables and DB I not working. In my test the results returned an empty database. This is the second time I am...
- How to bypass the rate limit on the back...
Once a month my app has a ton of usage and I always run into the Too many requests 429 error. I am trying to optimize the queues and jobs to manage that, but a...
- [SOLVED] Appwrite Cloud and FRA cloud se...
Can anyone estimate how long this will take to resolve? I am checking status here https://status.appwrite.online/