So the user Object has 5 attributes firstName , lastName,email,password and city.
I am getting the users with a method in class Users which is :
JavaScript
x
11
11
1
getUsersData () {
2
const usersMap = new Map()
3
this.users.get().then((data) => {
4
data.docs.forEach(user=> {
5
const {email , password} = user.data();
6
usersMap.set(email,password);
7
});
8
});
9
return usersMap;
10
}
11
which returns this in chrome console:
JavaScript
1
6
1
Map(0) {}
2
[[Entries]]
3
0: {"mehdiboujid@gmail.com" => "dqdqwdq"}
4
size: ( )
5
__proto__: Map
6
I am trying to use credentials in a Map because every user will have a unique email which will be the key to the map.
Advertisement
Answer
If this.users.get()
is async you will have to await
the result before returning the usersMap
.
JavaScript
1
11
11
1
async getUsersData() {
2
const usersMap = new Map()
3
await this.users.get()
4
.then((data) => {
5
data.docs.forEach(user => {
6
const { email, password } = user.data();
7
usersMap.set(email, password);
8
});
9
});
10
return usersMap;
11
}