Back

Registration and data table

  • 0
  • Databases
  • Web
  • Users
  • REST API
Р о м а
3 Dec, 2023, 07:17

Hi, tell me how I can do the following, I need each user to have their own data table, I don't understand how this can be implemented in this interface. I created a user in auth, after which what should I do to get the result? And after that, what should my request look like? Something like contacting the user, and choosing a table with data?

TL;DR
The user is asking for help implementing a data table for each user in their React Native app using Appwrite. They were initially unsure if a special SDK is needed for React Native. Other users suggest using the web SDK and provide an example code using the Users and Databases classes to create a user-specific table. The code allows authenticated users to access their own table but not other user's tables. The user is still unsure about the implementation steps and how to interact with the user-specific tables.
K_Vasen
3 Dec, 2023, 07:43

You could create the collections called users to store the user specific table i.e. documents with some attributes.

TypeScript
const users = new Users(client);

const dbs = new Databases(client);
const usersCollection = await dbs.createCollectio("<Your db Id>", ID.unique(), "users", [Permission.read(Role.users()), Permission.write(Role.users())]);

async function createUser(email, password, name){
  const user1 = await user.create(ID.unique(), "email", undefined, "password", "name") ;
  await dbs.createDocument("<YOUR DB ID>", usersCollection.$id, ID.unique(), {email, name}, [Permission.read(Role.user(user1.$id)), Permission.write(Role.user(user1.$id))]);
}

In the above code example. Any authenticated user can access the user collection but can't access other user documents

Р о м а
3 Dec, 2023, 08:13

thanks, but apparently you used an api here, but is it possible to do something similar with restApi? because there is no api for react native.

K_Vasen
3 Dec, 2023, 08:30

Yeah you could do the similar logic in restApi as well. Remember to include the permissions

Р о м а
3 Dec, 2023, 08:45

Great! Thank you very much

Drake
4 Dec, 2023, 12:45

What's your problem with using the web sdk?

Р о м а
4 Dec, 2023, 12:51

Perhaps) I'm just learning react native, and thought that a special sdk was needed for it. Thanks

Drake
4 Dec, 2023, 12:53

Since react native is JavaScript, you can usually use any library that works with JavaScript/react

Drake
4 Dec, 2023, 12:54

You'll sometimes run into problems though, like with file storage or oauth in Appwrite with react native

Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more