Once the user is successfully logged in, we will retrieve the user object from our Firebase database. On successful log in, we get the string uid
of the user and use this uid
to retrieve the user details from the user's node in the Firebase database. As discussed in the preceding section, we get the data in the JSON format as follows:
{ "email": "[email protected]", "mobile": "9972022242", "name": "Uttam Agarwal", "uid": "qu3bXn9tTJR7j4PBp9LzBGKxHAe2" }
This JSON object needs to be mapped to the user object. When we retrieve the JSON object from Firebase using AngularFireDatabase
, we provide the type object in angle brackets, <User>
and this maps the JSON to the user object:
public getUser(uid: string): Observable<User> { return this.fireDb.object<User>(`${USERS_CHILD}/${uid}`).valueChanges(); }
The constructor accepts all the parameters assigned to its member variable as shown in the following code; here's the complete user.ts
:
export...