Is there any code in wix wherein I can have like a facebook feature? Any members can post and other members can see the name of the owner (username) who have posted a content, the owner's profile picture and his comment or post. I kept on finding solution for this, but I haven't find one.
Hope someone could help me with this problem. 😓
Hi 🖐
You can use the getUser( ) function on the Backend to return any details about the user by passing its ID.
Backend Code
Create a function on the Backend to return user details to the Frontend:
export function getMemberDetails(userId) { return wixUsersBackend.getUser(userId) }
Fronend Code
Import and call the function to retrieve the user details from the Backend:
import { getMemberDetails } from 'backend/getMember.jsw'; import wixUsers from 'wix-users'; let userDetails = await getMemberDetails()
Make sure to call the function after the page is ready to avoid any possible errors.
Hope this helps~!
Ahmad
Have still a question to this topic.
Ok, i got my info from the "PrivateMembersData" with the help of Back-End-Command, but....
When i look at the API-REFERENCE and compare it with my given RESULTS, there are some differences.
This are the expected results, which should be given after the code has done his job.
/* Returns a promise that resolves to: * * { * "id": "dn8sf9c2-4e9f-a02d-a58d-f244d999729a", * "memberName": "John Doe", * "firstName": "John", * "lastName": "Doe", * "nickname": "johnd", * "slug": "johnd123", * "language": "en", * "status": "ACTIVE", * "loginEmail": "john.doe@somedomain.com", * "creationDate": "2019-08-05T11:29:39Z", * "lastUpdateDate": "2019-08-12T12:29:43.810Z", * "lastLoginDate": "2019-08-12T13:42:30Z", * "emails": [ * "john.doe@somedomain.com", * "doughyjohn@anotherdomain.com" * ], * "phones": [ * "5555555555", * "5555555556" * ], * "labels": [ * "contacts-new", * "contacts-site_members_approved" * ], * "picture": { * "url": "https://.../photo.jpg" * } * "customText": "Custom Text", * "customNumber": 12345 * } */
But this one is what i really get...
First-Name + Last-Name + Pic are not in my results.
Am i doing something wrong?
Comme le français voudrait dire, ET VOILA !
It works! xD
Now back to the shitty "PrivateMembersData" which makes me very often headaches!
Hello aero, yes i think it is possible exept the idea with the profile-pic.
In this case i am unsure.
Example-Situation: (little Brainstorming ---> how2 get what we need?)
I am a user on your site, and use a form to leave a comment. I will surely to have press aBUTTON to submit, to here we have already our event which will be the door to get what you want.
By pressing a button we can start a function:
function xxx () { } // you can name the function as you want, i am a lazy person, i just name it "xxx"
And now we wanna get our username of the current user who has created this new COMMENT (in this case its me) 😁
So where to find this information of the user? Of course in the "PrivateMemberData". So let's do it....
We have now several options how to get what we want, for example by quering the database of our choice ("PrivateMemberData") ....
import wixData from 'wix-data'; wixData.query("PrivateMemberData") .find() .then( (results) => { if(results.items.length > 0) { let firstItem = results.items[0]; } else { } } ) .catch( (err) => { let errorMsg = err; } );
Now you should have all the Information of "PrivateMemberData"
When you use CONSOLE.LOG, you can visualize all the data of this data-query.
console.log (results.items.title[0]) console.log (results.items.name[0]) console.log (results.items.firstName[0]) console.log (results.items.lastName[0]) //do not know exactly if this works ..... console.log (results.items.picture[0].url) //...or.... console.log (results.items.picture[0].link) //..to get the url of the Profile-Pic....
The last thing is to get this function be started by a klick on a button.
export function button1_click(event) {xxx()}
And now you can look at the results in the CONSOLE.
I did not test this CODE, so i hope it will run without any errors.