So I'm using appwrite for the first time and am trying to insert something to my db, however, I keep getting this error in the console:
AppwriteException: The current user is not authorized to perform the requested action.at Client.<anonymous>
I'm inserting the data without any user auth on the website - do I have to make an auth system? Or is there just something wrong with my api keys?
Also here's my code (I'm using SvelteKit):
<script>
import { Client, Databases, ID } from "appwrite";
import { client } from "$lib/appwrite";
import {
PUBLIC_APPWRITE_DB,
PUBLIC_APPWRITE_COLLECTION,
} from "$env/static/public";
let val= "";
const databases = new Databases(client);
function submit() {
const promise = databases.createDocument(
PUBLIC_APPWRITE_DB,
PUBLIC_APPWRITE_COLLECTION,
ID.unique(),
{ url: "test data", hash: "test data" },
);
promise.then(
function (response) {
console.log(response);
},
function (error) {
console.log(error);
},
);
}
</script>
<form
on:submit={(e) => {
e.preventDefault();
submit();
}}
>
<input
bind:value={val}
type="text"
/>
<button type="submit">submit</button>
</form>
Did you create a session using Account API before using the Databases APIs?
I think I did
Umm no, I dont see any login. See - https://appwrite.io/docs/products/auth/email-password
export const account = new Account(client);
So I have to log the user in before they can use the db?
If the Databases permissions are set to Users.
But how can I set the db permission so anybody can access it?
Your Database > Your Collection > Settings > Permissions > Manage the Permissions.
However, granting read/write/update permissions to Any, Guest, All Users isn't a good security practice. What are you trying to do?
Well thanks for that, this is just kind of a test project, so just a few ppl will look at it and have the access to the db therefor, you don't have to be worried about spam/bots
In that case, you could still do this - Permissions > All Users > Select permissions.
Ofc. this would require the users to register & login. For registration, you can manually add the users via Auth dashboard & mark them as Verified.
And if I'd do guest, anyone would have access to it without auth?
There a few gotchas here, for better info. see this doc - https://appwrite.io/docs/advanced/platform/permissions#permission-roles
alright, thanks
Recommended threads
- Collections list not showing up when try...
I'm trying to create new relationship attribute but both one way and two way relationship is not showing up collections list to connect with my relationship att...
- I have try to use the appwrite in to the...
Invalid Origin. Register your new client (oailedjdbkhlkakmnnapoonllbnfmfij) as a new Web (Chrome Extension) platform on your project console dashboard
- Weird permission failure
when creating an account I use following methods: ``` Future<void> register(String email, String password, String username) async { final user = await accoun...