Back

How to check if a name already exists

  • 1
  • Flutter
plushteddy
22 Feb, 2024, 14:26

Hello, how can I check if a name already exist?

TL;DR
Developers recommend creating a separate collection in Appwrite to store additional user data and then check for duplicates using a lookup. It is not recommended to expose API endpoints to the client or edit Appwrite source code for self-hosting. Storing names in preferences may not be effective as multiple users can have the same preference. The solution suggested is to use the server-side SDK to query the list of users and check if a name already exists.
Kenny
22 Feb, 2024, 14:29

I think to do something like this you would have to use the server side sdk and use the list users endpoint with a query of the persons name, and if it returns at least 1 record then a user exists with that name.

plushteddy
22 Feb, 2024, 14:31

so theres no way to do that within the flutter app?

Kenny
22 Feb, 2024, 14:34

I don't think so, the only other thing I can think of is if you were to set the ID of a user to their name, then Appwrite itself would prevent duplicates.

Kenny
22 Feb, 2024, 14:34

But that would also prevent you from allowing name changes.

plushteddy
22 Feb, 2024, 14:36

and what if I would save the name as a preference?

Kenny
22 Feb, 2024, 14:37

different users can have the same perference, so that wouldn't do anything for you

SHADOW07
22 Feb, 2024, 14:37

can you use collections in flutter ?

Kenny
22 Feb, 2024, 14:38

Like they've suggested, you could create a new collection to store additonal user data and use that to check for duplicates

SHADOW07
22 Feb, 2024, 14:38

by storing they emails

plushteddy
22 Feb, 2024, 14:38

yeah, but can you compare it there?

Kenny
22 Feb, 2024, 14:38

You cannot get any other users account data from the client sdk

plushteddy
22 Feb, 2024, 14:38

Lists?

SHADOW07
22 Feb, 2024, 14:39

i mean the collections in appwrite cloud

SHADOW07
22 Feb, 2024, 14:39

in the database

plushteddy
22 Feb, 2024, 14:45

maybe editing the appwrite source for self hosting would be the one with best performance?

Kenny
22 Feb, 2024, 14:46

I would not recommend exposing the endpoint to fetch other users data to the client.

plushteddy
22 Feb, 2024, 14:48

can I use the restapi to list the users?

Kenny
22 Feb, 2024, 14:54

https://appwrite.io/docs/references/cloud/server-rest/users

Sure, but you'll have to expose your api key.

Kenny
22 Feb, 2024, 14:57

I believe you would this be pretty much be exposing this data to anyone who wanted to look.

https://appwrite.io/docs/references/cloud/models/user

Kenny
22 Feb, 2024, 14:57

Which I would not recommend :P

Kenny
22 Feb, 2024, 14:58

I would go the route that Shadow had mentioned, create a seperate collection to store some additonal user data, key the collection on the user id and then you can easily do a lookup on that collection and see if a name already exists or not.

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