Hello! I am trying to create a document but getting this error:
pwrite.209ebd24.js:1 POST https://cloud.appwrite.io/v1/databases/646538e35dd17306c589/collections/646538eeeface7a4cd39/documents 401
(anonymous) @ appwrite.209ebd24.js:1
F @ appwrite.209ebd24.js:1
(anonymous) @ appwrite.209ebd24.js:1
(anonymous) @ appwrite.209ebd24.js:1
p @ appwrite.209ebd24.js:1
call @ appwrite.209ebd24.js:1
(anonymous) @ appwrite.209ebd24.js:1
(anonymous) @ appwrite.209ebd24.js:1
p @ appwrite.209ebd24.js:1
createDocument @ appwrite.209ebd24.js:1
I @ create.f48802b9.js:1
create.f48802b9.js:1 AppwriteException: The current user is not authorized to perform the requested action.
at Pe.<anonymous> (https://pitchfork.vercel.app/_astro/appwrite.209ebd24.js:1:19652)
at Generator.next (<anonymous>)
at c (https://pitchfork.vercel.app/_astro/appwrite.209ebd24.js:1:14540)
Have you add write permissions for the 646538eeeface7a4cd39 collection?
Here is the code:
<script lang="ts">
import { appwriteStorage,appwriteDatabases,appwriteUser } from "../lib/appwrite";
import { ID , Role, Permission } from "appwrite";
export let userID = '';
let IconID = ID.unique();
let ThumbnailID = ID.unique();
let IconUpload = document.getElementById('IconFile') as HTMLInputElement;
let ThumbnailUpload = document.getElementById('ThumbnailFile') as HTMLInputElement;
let PostTitle = '';
let PostTagline = '';
let PostDescription = '';
let PostLink = '';
let Icon = [] as any;
let Thumbnail = [] as any;
let IsFree = true;
let PostLaunchDate = Date.now();
async function UploadIcon() {
if (IconUpload.files) {
Icon = await appwriteStorage.createFile('646547f5019189c8092b',ID.unique(),IconUpload.files[0]);
}
}
async function UploadThumbnail() {
if (ThumbnailUpload.files) {
Thumbnail = await appwriteStorage.createFile('646547f5019189c8092b',ID.unique(),ThumbnailUpload.files[0]);
}
}
async function CreatePost() {
appwriteDatabases.createDocument(
'646538e35dd17306c589',
'646538eeeface7a4cd39',
ID.unique(),
{
'title': PostTitle,
'tagline': PostTagline,
'description': PostDescription,
'link': PostLink,
'isFree': IsFree,
'launchDate': PostLaunchDate,
'userID': userID,
'Icon': IconID,
'Thumbnail': ThumbnailID
},
[
Permission.read(Role.any()),
Permission.write(Role.user(userID)),
Permission.delete(Role.user(userID)),
Permission.update(Role.user(userID)),
Permission.delete(Role.team("Owner")),
Permission.update(Role.team("Owner")), Permission.read(Role.team("Owner")), Permission.delete(Role.team("Admin")), Permission.update(Role.team("Admin")),
]
).then((response) => {
console.log(response);
UploadIcon();
UploadThumbnail();
}, (error) => {
console.log(error);
});
}
</script> ```
here are my perms
I mean in the collection settings?
Good
Now you need to add some way for use to create document
Either by allow the create permission or inside a cloud-function
What do you mean?
Here you've let Any to read
Right?
like this
Yes
oh
Exactly
let me try now
do I have it do the same for the buckets?
why is it giving me the error again? tps://cloud.appwrite.io/v1/databases/646538e35dd17306c589/collections/646538eeeface7a4cd39/documents 401 (anonymous) @ appwrite.209ebd24.js:1 F @ appwrite.209ebd24.js:1 (anonymous) @ appwrite.209ebd24.js:1 (anonymous) @ appwrite.209ebd24.js:1 p @ appwrite.209ebd24.js:1 call @ appwrite.209ebd24.js:1 (anonymous) @ appwrite.209ebd24.js:1 (anonymous) @ appwrite.209ebd24.js:1 p @ appwrite.209ebd24.js:1 createDocument @ appwrite.209ebd24.js:1 I @ create.f48802b9.js:1 create.f48802b9.js:1 AppwriteException: Permissions must be one of: (any, users, user:64664a3a1e3479d80c32, user:64664a3a1e3479d80c32/unverified, users/unverified) at Pe.<anonymous> (https://pitchfork.vercel.app/_astro/appwrite.209ebd24.js:1:19652) at Generator.next (<anonymous>) at c (https://pitchfork.vercel.app/_astro/appwrite.209ebd24.js:1:14540)
Can you remove the any and try?
Yes
From the code or the website
From the console
But, Sorry In this code
[
Permission.read(Role.any()),
Permission.write(Role.user(userID)),
Permission.delete(Role.user(userID)),
Permission.update(Role.user(userID)),
Permission.delete(Role.team("Owner")),
Permission.update(Role.team("Owner")),
Permission.read(Role.team("Owner")),
Permission.delete(Role.team("Admin")),
Permission.update(Role.team("Admin")),
]
You can't add these line
Permission.delete(Role.team("Owner")),
Permission.update(Role.team("Owner")),
Permission.read(Role.team("Owner")),
Permission.delete(Role.team("Admin")),
Permission.update(Role.team("Admin")),
When you're running against Appwrite from a client side SDK (like Web) you can't set any permission that you don't own. For example in your use case these are the only one you can set from the client side
- any, users, user:64664a3a1e3479d80c32,user:64664a3a1e3479d80c32/unverified, users/unverified
AppwriteException: Permissions must be one of: (any, users, user:64664a3a1e3479d80c32, user:64664a3a1e3479d80c32/unverified, users/unverified)
If you do want to be able to add and declare as many permissions as you like You can do so, but, for that you'll need to use Appwrite function + Server side SDK
Hope this makes sense
Recommended threads
- TablesDB `updateRows` returns `database_...
Hi Appwrite team! I’m seeing a strange issue with TablesDB bulk row updates on a self-hosted Appwrite instance. **Environment** - Appwrite self-hosted `1.9.0` ...
- [SOLVED] Realtime Missing Channels
```js useEffect(() => { let subscription: RealtimeSubscription; async function loadChips() { try { const {rows: chi...
- Functions executed by events does not ap...
Hello, Running self-hosted Appwrite version 1.9.0 (with console 7.8.26). When functions are triggered by an event (eg. databases.\*tables.\*.rows.\*.create) doe...