I am currently immersed in a project that involves Cloud 9 and Ionic, with a Firebase database at its core. My main challenge lies in referencing the specific details of a particular vehicle (as per the database layout) and then displaying this information on a webpage.
{
"userProfile" : {
"fjN6auulwkguoB4SsUKyiKXZzNx1" : {
"birthday" : "1997-06-12",
"drivers" : {
"-KqbyzU_KKYtpmewoDza" : "Test"
},
"email" : "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="ee848f9d8180ae9a8b9d9ac08d8183">[email protected]</a>",
"licenseNum" : "1234",
"name" : "Tester",
"password" : "123456",
"surname" : "Test",
"vehicles" : {
"-Kqbywf6e8VkojtLTUyi" : {
"location" : "Stellenbosch",
"make" : "Mercedes-Benz",
"mileage" : "123",
"model" : "SLK",
"year" : "2017"
},
"-Kqc-yYdd5DKnodnAWe6" : {
"location" : "ste",
"make" : "BMW",
"mileage" : "123124",
"model" : "dfg",
"year" : "2016"
}
}
Essentially, each user has a unique key assigned by the database, containing attributes such as email and birthday. The objective is to identify the current logged-in user to access their unique key, followed by displaying all vehicles associated with that user. Clicking on a specific car should lead to a new page showcasing detailed information about the selected vehicle. I'm facing difficulties in referencing the vehicle key and passing those specifics to the respective page. The code snippet below from "client-profile.ts" allows me to display user details:
export class ClientProfilePage {
private userPhotoUrl:any;
private userDisplayEmail : any;
private userDisplaysName : any;
private userDisplayName : any;
private userDisplayBirth : any;
private userDisplayLicense : any;
constructor(public navCtrl: NavController, private AuthProvider: AuthProvider) {
var myUserid= firebase.auth().currentUser.uid; //current user id
this.displayUser(myUserid);
}
displayUser(theUserId){
var that = this;
this.AuthProvider.viewUser(theUserId).then(snapshot => {
that.userDisplayEmail= snapshot.val().email;
that.userDisplayName= snapshot.val().name;
that.userDisplaysName= snapshot.val().surname;
that.userDisplayBirth= snapshot.val().birthday;
that.userDisplayLicense= snapshot.val().licenseNum
})
}
The related code from "auth.ts" is provided below:
export class AuthProvider {
public fireAuth:firebase.auth.Auth;
public userProfileRef:firebase.database.Reference;
public userProfile:firebase.database.Reference;
constructor(public http: Http) {
this.fireAuth = firebase.auth();
this.userProfileRef = firebase.database().ref('/userProfile');
}
loginUser(email: '', password: ''): firebase.Promise<any>{
return this.fireAuth.signInWithEmailAndPassword(email, password);
}
viewUser(userId: any){
var userRef = this.userProfileRef.child(userId);
return userRef.once('value');
}
Any assistance or guidance would be greatly appreciated!