opentrace-community / opentrace-android

OpenTrace Android app. Reference implementation of the BlueTrace protocol.
https://bluetrace.io
GNU General Public License v3.0
577 stars 225 forks source link

Creation of 'users' collection and adding a new user to database after registration #39

Closed vishaljoseph closed 4 years ago

vishaljoseph commented 4 years ago

Hi,

How would I go about creating a 'users' collection and adding a new user's details to the collection after successful registration? To be more specific, where exactly would I have to put in the code for writing to the DB?

alexissinglaire commented 4 years ago

@vishaljoseph : are you trying to create database colllection to store the user information locally in the android device?

vishaljoseph commented 4 years ago

Nope, want to store it on the cloud. But it would be very helpful to know how I could store it locally as well.

alexissinglaire commented 4 years ago

@vishaljoseph : in the cloud specifically for google cloud, you can choose firestore or datastore to store the information. you can refer to following link for comparison between firestore and datastore.

https://cloud.google.com/datastore/docs/firestore-or-datastore

you can refer to this link for sample on firestore integration for android app. https://github.com/firebase/FirebaseUI-Android

as for datastore can only be done via scripting or programming in the google cloud itself (refer to the comparison between firestore and datastore)

PS: I believe this question actually not an issue related with the functionality of this app. But it;s more some query related to other technology implementation that you want to add to this app.

vishaljoseph commented 4 years ago

Thanks @alexissinglaire . Yes, that's right. I am trying to include some additional functionality. I expected that the opentrace code would include creation of 'users' collection in the db since there is a mention of Firestore. I was planning on using the following line of code to add users to the db:

admin.firestore().collection('users').doc('userid').set({'attribute1': x, 'attribute2':y})

Adding this in the OnboardingActivity.kt seems to make sense to me, but I'm confused on how to retrieve the user details after OTP verification.

alexissinglaire commented 4 years ago

@vishaljoseph : what kind of user detail you need to retrieve? are you referring to information from firebase authentication such as application token, uuid token?

currently the user registration using mobile phone is done using firebase authentication API. you can refer to following link for more information on the API.

https://firebase.google.com/docs/reference/android/com/google/firebase/auth/package-summary

hope it help.

vishaljoseph commented 4 years ago

I want the following for now: userid and phone number. Once this is retrieved, I want to store it in the db.

alexissinglaire commented 4 years ago

@vishaljoseph :

you need to retrieve the firebase instance as following: FirebaseUser fUser=FirebaseAuth.getInstance().getCurrentUser();

to get user UUID and email address, you can refer to following sample:

String userUUID = fUser.getUid(); String userEmailAddress = fUser.getEmail(); String phoneNumber = user.getPhoneNumber();

Hope it helps.

vishaljoseph commented 4 years ago

Yes, works perfectly. Thanks again!