Hi everyone! Hope you are all safe and doing fine during these days.
I’m having some problem with my backend until now.
I noticed that my current code below which I named getMember.jsw only get the details from Members/PrivateMembersData and not in my own database 'cause I’m planning to use this to get the owner’s data from my own database ( MemberPage ).
import wixUsersBackend from 'wix-users-backend';
export function getMemberDetails(userId) {
return wixUsersBackend.getUser(userId);
}
//This worked but it gets the data from Members/PrivateMembersData not in MemberPage
I tried to create my own code but it didn’t work. I’m not really good at backend coding
import wixData from 'wix-data';
export function getMemberDetails(userId) {
return wixData.query('MemberPage')
.eq('_id', userId)
.find()
}
//This didn't work and didn't get the data from MemberPage
Hope someone can help me with this one. I really need help guys…
Hello Juan.
Your thoughts are NOT COMPLETE!
You have 2-DATABASES!
- PrivateMembersData
- Your own database → MemberPage.
What are you trying to do ?
Explain a little bit your project and the structure of your own database.
@russian-dima Thanks for replying!
I wanted to use the backend to pull the data from my MemberPage, and use it to export owner’s data so that the owner’s post can be seen with the owner’s username, and profile picture, and not the owner’s username and profile picture in Members/PrivateMembersData
@aeroengineerz7
Working on a comment-box?
Step-1: Getting the right logged in user… (you do not need the back-end in your case, because you are working with your own databse and not with PMD)
import wixUsers from 'wix-users';
let user = wixUsers.currentUser;
let userId = user.id;
let isLoggedIn = user.loggedIn;
user.getEmail()
.then( (email) => {
let userEmail = email;
} );
Step-2: After you have the current-users-ID you have to find this ID in your own database —> “MemberPage” (filtering-process).
wixData.query("MemberPage")
.eq('_id', userId)
6 .find()
7 .then( (results) => {
8 if(results.items.length > 0) {
9 let firstItem = results.items[0];
let items = results.items
console.log(items)
10 } else {
11 // handle case where no matching items found
12 }
13 } )
14 .catch( (err) => {
15 let errorMsg = err;
16 } );
Console should show the founded result(s).
Yes, I’m still working on it because I stopped for so many days… doing some things.
Oh okay!.. so I don’t need to use the backend when not using PrivateMembersData
Thanks again! I’ll try it tomorrow.