Deleting user profile from firestore database along with Firebase Auth

The points 1 & 2 are same as like you in my project.
But the third point, there is different than yours…Let me elaborate.

In my case, when an user register(sign-up) on my app, he needs to provide a Name+email id + Password and hit enter to register. Am using Firebase Rest API HTTP request to register user here. You can see Sign-Up HTTP flow function on the screenshots above.

I connected the next flow function Get current user to the signup flow then assign the output of get current user to a appVars UID with value uid from the output. Then your part comes… HTTP request with PATCH… to create record on my firebase DB.

Is am on the right path @F_ORTELL ?

Yes you’re on the right path, what need is to be able to create any record n firestore using http request… If can manage that, then you can add custom keys to the request and the body.just do a simple record to send. That way you’ll know where the problem is. Also make a toast that shows response code or message.

I think you understand wrong(because of my poor explanations). I didn’t create record using HTTP request, I said that I can create request by using “Create Record” flow function by adding Data Variable, but in this case document ID of my record is generated automatically by firestore itself @F_ORTELL

OK,now I get it, you can’t set custom id to records using create records flow function for now, it only works with http request.

Instead of create record flow function, use http request…

Set url as

“https://firestore.googleapis.com/v1/projects/MyappgyverProject/databases/(default)/documents/Users/”+appVars.uid

Method as patch

Request body as


{

“fields”: {

             "firstname": {"stringValue": "hello"} ,
             "lastname": {"stringValue": "world"}
                } 

}

Send it to Firestore and tell me what it says or does

That’s what I did here Deleting user profile from firestore database along with Firebase Auth - #16 by Bravo_Moossa

I am just telling you that I am able create record using create record flow function that create record using auto document ID…

But the HTTP request with PATCH method from your instruction wont work in my App, that’s what I am saying to you. If it works, then only I can create document in firebase with Document ID as UID like you said. @F_ORTELL

ok, I can try that also. I have one more doubt @F_ORTELL

Do I need to create record first using HTTP request POST method and then again use another HTTP request with PATCH method to set the custom ID to the record?

1 Like

No, patch is a better way, it creates and updates at the same time…
If you don’t have a record, it creates it, if it is there, it updates it

Maybe there’s something wrong with the code I sent,but I can’t test it coz I left my pc. However, you use http request to send data with custom id… Look for other posts talking about setting custom id in the forum, um sure you can find something.

No, it was perfect code that you share…

I did it @F_ORTELL Thank you very much for your support, really appreciate that.
The problem is with my appVars, use toast on all the node to track the flow. Then I realize that they stop at appVar that I has set before HTTP request. Digging on that I got the solution and fixed the issue.

Now I can create or update record using PATCH method with custom ID. Thanks again.

That’s great, let me know if you need help with anything here, I’ll help if I know how to solve it…
Thanks

Hi F_ortell, I used the url as your suggested and used patch for my Http request. When I login, it creates a new record in firestore instead of updating the existing record. Does it meant to update the existing record by replacing the auto id generated with the user id?

The patch method updates a record if you try to create a record that exists in your firestore collection…

The reason why it creates at new document is because the ID is new

Use UID from firebase Auth as the ID for your user details documents in Firestore

Hi F_ortell, thanks for your prompt reply.

I don’t quite understand your last reply, could you please explain a little further?

I get the firebase id from the Email & password authentication flow function and set it as an app variable, then I use the url you provided to try to update (patch method) the current auto generated document id with the user id. In my document, I only have the email and password fields under the user.

The fire Auth and the document have to share the same ID… You create user documents with the UId you get from Auth.

“https://firestore.googleapis.com/v1/projects/MyappgyverProject/databases/(default)/documents/Users/”+appVars.uid

Attention to the The url above, it takes appVars.uId (UID from fire Auth) as a parameter and use it to create a record, it will set the id of that record to the value in appVars.uid as document ID

Take screenshot of your Auth and collection, I can advise you better if i see what you trying to do





As you can see I have followed your instruction but I can’t replace the existing record. Hopefully you can see where I went wrong. Thanks.

If you hover to the image, you can see its caption .

OK I see where it issue is…


Look at the screenshot here, the user documents has the same ID at the Auth