Back

[SOLVED] unable to delete user

  • 0
  • Users
  • Accounts
  • Web
  • Cloud
Susmita
22 May, 2023, 15:31

Function is not getting executed on button click

TL;DR
User is having issues with deleting a user in their code. They are also trying to get the total number of items in a collection. They receive an error when executing a function on button click. The solution provided is to check that the 'id' has the correct value and to add permission for any user to execute the function.
Susmita
22 May, 2023, 15:31

Current Code:

Binyamin
22 May, 2023, 15:32

Verify that id actually has the right value Like so

TypeScript
 const deleteUser = (id) => {
    console.log(id);
    if(id === undefined){
      return;
    }
    const promise = functions.createExecution('646b801508edd4a42aba', id);
    promise.then(
      function (response) {
        setUserDetails(response);
        console.log(response);
        router.push('/');
      },
      function (error) {
        console.log(error);
        // window.location.reload();
      }
    );
  };
Susmita
22 May, 2023, 15:35

Here comes the error now

Binyamin
22 May, 2023, 15:38

Good, Just add permission for any User to execute the function

Binyamin
22 May, 2023, 15:38
Susmita
22 May, 2023, 15:39

It worked

Susmita
22 May, 2023, 15:39

Thanks

Susmita
22 May, 2023, 15:39

Need another help on the same page

Susmita
22 May, 2023, 15:40

For this specific part:

TypeScript
const getCount = async (collection_id) => {
         const list = await databases.listDocuments("646605464de2f5cb7435", collection_id);
         const stats = `total is: ${list.total}`;
         return stats;
     }
Susmita
22 May, 2023, 15:40

Full code is above

Binyamin
22 May, 2023, 15:41

What's the problem?

Susmita
22 May, 2023, 15:42

It was showing undefined

Susmita
22 May, 2023, 15:42

Actually the thing is the document is not getting created

Susmita
22 May, 2023, 15:42

For which it might be such thing

Binyamin
22 May, 2023, 16:08

So this one works for you?

Susmita
22 May, 2023, 16:14

delete user is working

Susmita
22 May, 2023, 16:14

Document is also getting created

Susmita
22 May, 2023, 16:15

I'm now trying to get the total no of items in the collections of todolist

Susmita
22 May, 2023, 16:15
TypeScript
<div className='text-gray-500'>
                                    <p>No of Todo items: {getCount("6466055dd831efd150ef")}</p>
                                </div>
Binyamin
22 May, 2023, 16:27

Okay, but getCount is async function And you want it to return into the components? I think for that you'll need to use other field in your state use it inside your HTML and update it in the getCount function

Susmita
22 May, 2023, 16:27

yes

Susmita
22 May, 2023, 16:28

like a new useState?

Binyamin
22 May, 2023, 16:34

Yes

Susmita
23 May, 2023, 06:33

[SOLVED] unable to delete user

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