Yusuf gndz
Yusuf gndz

Reputation: 137

How can I post my data without generating firebase id on firebase realtime database?

I am trying to push my user's authentication id to realtime database to easily get them both in same time but realtime database keep generating id under UUID.

  Future<http.Response> createUserProfile(
    String id,
    String email,
    String userName,
  ) async {
    return await http.post(
      ServiceKeys.FIREBASE_URL + "/users/$id.json",
      headers: <String, String>{
        'Content-Type': 'application/json; charset=UTF-8',
      },
      body: jsonEncode(<String, String>{'name': userName, 'email': email}),
    );
  }
}

Firebase generated data tree id

I don't want "-MCHpnJZnKvth-L89axu" to be generated. but instead directly write it into id that I provided.

Upvotes: 0

Views: 1003

Answers (1)

Candace
Candace

Reputation: 81

Try using put instead of post. Firebase API says

POST: Add to a list of data in our Firebase database. Every time we send a POST request, the Firebase client generates a unique key, like messages/users//

and

PUT: Write or replace data to a defined path, like messages/users/user1/

Since you have the uid already, it would be a defined path

Upvotes: 1

Related Questions