#bug with permissions on react native

34 messages · Page 1 of 1 (latest)

spiral mason
#

Hi when i set on a table some permission like all users read and write and then from the sdk I try to add a new row in that table I get this error: AppwriteException: The current user is not authorized to perform the requested action.
even though the row is actually added. the same happens also when i enable the row security and I specify the correct permission roles, because the row is then added or modified but i still get the error.

paper lintel
#

If you don't have any problem, can you share the setup? i.e. the code where you've specified the permissions?

spiral mason
sour parcel
#

So it is working but also throwing an error?

spiral mason
sour parcel
spiral mason
sour parcel
#

Try giving all permission to any

spiral mason
sour parcel
#

Could you share the sdk version?
I will try to reproduce it tommorow and file a bug report if needed.

spiral mason
sour parcel
spiral mason
sour parcel
paper lintel
spiral mason
paper lintel
#

And this -

paper lintel
#

@spiral mason And one more important thing, does your API key have all the required permissions?

spiral mason
spiral mason
# paper lintel Can you share the complete code of the file where you've this?

import { Query, Models, ID, Permission, Role } from 'react-native-appwrite';
import { account, tables, appwriteConfig, functions } from './appwrite';
import { AppwriteProduct, ScannedProduct, Subscription, UserProfile, FeatureRequest } from '../types/product';

const getCurrentUserId = async (): Promise<string | null> => {
try {
const user = await account.get();
return user?.$id ?? null;
} catch (error) {
return null;
}
};

spiral mason
# paper lintel And this -

import { tables, appwriteConfig } from './appwrite';
import { Query, ID, Models, Permission, Role } from 'react-native-appwrite';
import { getCurrentUserId } from './appwriteService';

export const savePrice = async (productId: string, price: number, isConfirmed = false): Promise<void> => {
const userId = await getCurrentUserId();
if (!userId) {
throw new Error('User not authenticated');
}

const normalizedPrice = Number(Number(price).toFixed(2));

const payload: Record<string, unknown> = {
product_id: productId,
price: normalizedPrice,
currency: 'EUR',
is_confirmed: isConfirmed,
user_id: userId,
recorded_at: new Date().toISOString(),
};

try {
await tables.createRow(
appwriteConfig.databaseId,
appwriteConfig.tables.prices,
ID.unique(),
payload,
);
} catch (err) {
console.error('savePrice failed', err);
throw err;
}
};

paper lintel
#

Ok. Can you try writing this part of your code -

await tables.createRow(
    appwriteConfig.databaseId, 
    appwriteConfig.tables.prices, 
    ID.unique(), 
    payload,
);

like this -

await tables.createRow(
  appwriteConfig.databaseId,
  appwriteConfig.tables.prices,
  ID.unique(),
  payload,
  [
    Permission.read(Role.users()),
    Permission.update(Role.user(userId)),
    Permission.delete(Role.user(userId)),
  ]
);
spiral mason
paper lintel
spiral mason
spiral mason
sour parcel
spiral mason
#

okay i found the issue, in one of the relationship tables I had the create permission disabled, so even if I didn't write in it since it was a relationship it was giving the error