Skip to content
Back

[Solved] trouble deleting users

  • 1
  • Users
  • Flutter
  • Functions
๐ŸœUdon๐Ÿœ
17 May, 2023, 15:40

Hello I've been wondering if it's possible to delete a user from the Auth menu. I was able to write a cloud function that gets the uid and runs Users.delete(uid) doesn't delete the user in the Auth tab of the appwrite console. Would love to hear from other people more experienced

TL;DR
The user is having trouble deleting a user from the Auth menu using the `Users.delete` function. The function returns an error saying "user role: guests" "account required". They are sharing their code and asking for help from more experienced users. Someone suggests that they may be calling the function incorrectly and asks for more details about the code. The user shares their code and mentions that they are using a http POST to send the uid to the function. Another member suggests that they may need to change a few things, including removing the `X-Appwrite-key` header in the flutter code and changing the `deleteUserFunctionId`
Binyamin
17 May, 2023, 15:47

What was the results of the Users.delete function?

๐ŸœUdon๐Ÿœ
17 May, 2023, 15:49

It says "user role: guests" "account required"

Binyamin
17 May, 2023, 15:50

Can you share the code of the function?

๐ŸœUdon๐Ÿœ
17 May, 2023, 15:50

I'm calling the function wrong I think. I'm using a http POST

๐ŸœUdon๐Ÿœ
17 May, 2023, 15:50

Sure

๐ŸœUdon๐Ÿœ
17 May, 2023, 15:52
๐ŸœUdon๐Ÿœ
17 May, 2023, 15:54

That's the function I'm using dart for it

๐ŸœUdon๐Ÿœ
17 May, 2023, 15:54

And here is how I'm sending the uid to it

Binyamin
17 May, 2023, 15:55

What did you put inside the deleteUserFunctionId variable?

๐ŸœUdon๐Ÿœ
17 May, 2023, 15:55
๐ŸœUdon๐Ÿœ
17 May, 2023, 15:56

The payload I was trying to send

๐ŸœUdon๐Ÿœ
17 May, 2023, 15:56

I'm probably doing this all wrong and there's a simple way of passing the uid to the function

Binyamin
17 May, 2023, 15:57

This code is inside the App in your flutter project?

๐ŸœUdon๐Ÿœ
17 May, 2023, 15:59

The first one is a function folder I deployed and the second one inside my flutter app lib folder both are in my flutter project

Binyamin
17 May, 2023, 16:00

Okay, good

๐ŸœUdon๐Ÿœ
17 May, 2023, 16:00

Awesome

๐ŸœUdon๐Ÿœ
17 May, 2023, 16:01

Not sure if the second one is right but I think the first one is since I followed the documentation for it

๐ŸœUdon๐Ÿœ
17 May, 2023, 16:02

I just tried sending the uid string using http as a payload and I think that's the problem

๐ŸœUdon๐Ÿœ
17 May, 2023, 16:03

Not sure how other appwriters send uids and other stuff to functions

Binyamin
17 May, 2023, 16:03

So you'll need to change a few things.

First you can if you want to use Appwrite flutter package (https://appwrite.io/docs/getting-started-for-flutter)

API Key The API key let's you access Appwrite resource on a server level https://appwrite.io/docs/sdks#server That's means that unless you have a very good reason for that you only use this key in server side code as your function.

Flutter So, In your flutter code (App) when execution a function you should remove the X-Appwrite-key header.

Function In your function I think that you'll need to to change the line 34 in which you're using the deleteUserFunctionId constant to delete_user_API one

Binyamin
17 May, 2023, 16:03

Is this make sense?

๐ŸœUdon๐Ÿœ
17 May, 2023, 16:07

Yup makes sense didn't know the header part and I think you're right about changing the deleteUserFunctionId to delete_user_API

๐ŸœUdon๐Ÿœ
17 May, 2023, 16:07

Going to try them out now

Binyamin
17 May, 2023, 16:08

It can be confusing at start

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