Hi! I’m working on creating a comment section for my website. But, for some reason, the member reference get a “broken reference”. I’ve been searching through the Wix forum and I couldn’t find a solution. Some say it is a .id problem, but in my case it doesn’t because I have the ID placed correctly. Does anyone know how to fix this?
Thanks in advance.
Code:
memberReference : wixUsers . currentUser . id, is where the broken reference occurs. For some reason, it doesn’t work.
Can you paste the code here so we can take a better look?
Here s a photo of the comment section inside a dynamic product page:
Comments database:
And Member database:
Ok, so the error is related to the reference itself. This Members Collection that you have, it is not the same one that WIX Users API is using for login. You can check the ids to see the difference. Usually the WIX Users API gets the user from the PrivateMembers Collection, if I’m not mistaken.
Try console.log(wixUsers.currentUser.id) and compare the returned id with the one in the Members collection.
Hi! Thanks for the quick reply
!
You are correct. I just checked the consol.log and the member collections. Both aren’t using the same user stats. The users ip in the member collection and the comment collection are different to one other.
I didn’t know about the Private member’s collection. Is the private members collection a default collection. If so, where can I find it? I ll try to fix it with tests. But, if you know to fix this, could you tell me the way to fix this please?
Thanks very much for the help 
Maelor
Hi! Sorry, I just found out that the code wasn’t send. When I try to send the code, this pop-up appears. And, I don’t have any www. Address posted to it. : Your account does not currently allow posting of links. If you need to post a link of your site and relevant Wix content, break the link like this: www.wix . com/velo
Is there any way I can send you the code?
@suomai777iamous You need to copy and paste it here. I’m pretty sure it is possible.
One other thing, did you create the Members Collection?
@bwprado Hi! Yes I created the Members collection.
Here’s the comment section code. I had to publish it separately (everything is in order) because Wix forum didn’t allow me to publish it all together.
Comment section code:
import wixData from ‘wix-data’ ;
import wixUsers from ‘wix-users’ ;
// comments count
$w . onReady ( function () {
// TODO: write your page related code here…
setTimeout ( function () {
let totalCount = $w ( “#Reviews” ). getTotalCount ();
$w ( ‘#text157’ ). text = totalCount . toString () + " comments"
}, 5000 );
});
export function button51_click ( event ) {
$w ( '#loader' ). show ()
$w ( '#button51' ). disable ()
**let** page = $w ( "#dynamicDataset" ). getCurrentItem ();
**let** pageId = page._id ;
wixData . insert ( 'comments' ,{
@bwprado Some word have a space in between because it doesnt allow me to publish it al toguether.
‘comment’ : $w ( ‘#textBox1’ ). value . replace ( ‘fuck’ , ‘f*ck’ ),
‘currentUserId’ : wixUsers . currentUser . id ,
‘pageId’ : pageId ,
‘pageReference’ : pageId ,
‘memberReference’ : console . log ( wixUsers .currentUser . id ,)
})
@bwprado
. then ( () => {
$w ( '#textBox1' ). value = ''
$w ( '#Reviews' ). refresh ()
setTimeout ( **function** () {
$w ( '#button51' ). enable ()
$w ( '#loader' ). hide ()
**let** totalCount = $w ( "#Reviews" ). getTotalCount ();
$w ( '#text157' ). text = totalCount . toString () + " comments"
}, 2000 );
})
}
Sorry for having to send it like that.
Maelor
@bwprado And here’s the member system coded:
(Many words have a space in between in order for wix forum to allow me to publish it).
import wixUsers from ‘wix-users’ ;
import wixData from ‘wix-data’ ;
import wixLocation from ‘wix-location’ ;
$w . onReady ( () => {
if ( wixUsers . currentUser . loggedIn ) {
$w ( “#loginButton” ). label = “Logout” ;
$w ( “#profileButton” ). show ();
} else {
$w ( “#loginButton” ). label = “Login” ;
$w ( “#profileButton” ). hide ();
}
} );
export function loginButton_click ( event ) {
// user is logged in
if ( wixUsers . currentUser . loggedIn ) {
// log the user out
Promise . all ( [ wixLocation . to ( ‘/#page1’ ), wixUsers . logout () ] )
. then ( () => {
// update buttons accordingly
$w ( “#loginButton” ). label = “Login” ;
$w ( “#profileButton” ). hide ();
} );
}
// user is logged out
else {
let userId ;
let userEmail ;
// prompt the user to log in
wixUsers . promptLogin ( { "mode" : "login" } )
. then ( ( user ) => {
userId = user . id ;
**return** user . getEmail ();
} )
. then ( ( email ) => {
// check if there is an item for the user in the collection
userEmail = email ;
**return** wixData . query ( "Members" )
. eq ( "_id" , userId )
. find ();
} )
. then ( ( results ) => {
// if an item for the user is not found
**if** ( results . items . length === 0 ) {
// create an item
**const** toInsert = {
"_id" : userId ,
"email" : userEmail
};
// add the item to the collection
wixData . insert ( "Members" , toInsert )
. **catch** ( ( err ) => {
console . log ( err );
} );
}
// update buttons accordingly
$w ( "#loginButton" ). label = "Logout" ;
$w ( "#profileButton" ). show ();
} )
. **catch** ( ( err ) => {
console . log ( err );
} );
}
}
export function profileButton_click(event) {
wixLocation . to(`/members/${wixUsers. currentUser. id}`);
}
I don’t understand why it doesn’t allow me to send it all together. I can send it to you with Google Docs email.
Thanks a lot for you time
Maelor.
@bwprado Hi! I’ve sent the Google Docs to your email.
So, as you created your own Members Collection, you would have to create your own login page and login auth or OAuth. WIX Users API cannot use your Members Collection.
Now, that would be really complicated, not recommended for most of WIX Users. What I think you should do is use WIX Auth and WIX Users instead and don’t even need the Members collection. Every comment or post created by a user of your website, will generate a Owner field in the Post or Comments Collection.

You can use that field to show whose comment/post is.
I fixed your code but now, it won’t have that reference.
So, without the member’s collection, where will I store the profile picture, data, etc. I only had the member’s collection just to store email, profile picture and a few users setting for the purpose of the website.
I used two tutorials to create the member system and the comments’ system.
-Member system: https: // www . youtube. com /watch?v=5ljNhQOsZKE&t
-Comment system: https: // www . youtube. com / watch?v=lLZPi8crR_M
The member system looks great, and I added in a lot of features for the site.
And the comment system is the one that just doesn’t work:/.I ll have to remove the comment feature.
With the standard Wix member app, I just don’t have much control over the data that I have to manage…
Anyway, thanks very much for the help and for your time.