wixUsers.currentUser.id

Hi

The following seems to bring back the ‘owner’ rather than ‘user’ ID:

$w(“#button6”).label = wixUsers.currentUser.id;

I use the button to just display the value of the variable but the operational code is below (and it doesn’t seem to work):

wixLocation.to(/Alumni_Members/MemberInfo/${wixUsers.currentUser.id});

Where am I going wrong? Any ideas??

Thank you

Too hard?

By default the database seems to point to the latest record if it cannot find the user ID. This isn’t what is needed.

I’ll try the email as an option but it would be nice id user.id worked.

Hi,
Do you get the right results from wixUsers.currentUser.id ; ?
Are you sure you copied the url properly from the dynamic page’s settings?

Thank you for your advice. I think I uncovered one possible problem: /Alumni_Members/MemberInfo/${ wixUsers.currentUser.id } gets converted in the system to /Alumni-Members/… (underscore to minus character).

So I think that is fixed.

In the preview function the correct record is now found but when published the system goes back to the top record on file.
I tried moving the export function profileButton code from the bottom of the script to the top - nothing changed.

I then inserted a known userId code (hard wired, I thought) in various places in the script and this works in PREVIEW but not published mode

In the published mode the following debug button shows the correct user ID:

$w(“#button6”).label = wixUsers.currentUser.id; //control

but

hovering over the #profileButton shows up a reference to the top record in the database, not the linked record.

The button code settings:

Connect dataset: Alumni_Members dataset
Label Connects to: Not Connected
Link Connects to: Alumni_Members MemberInfo (ID)

Observation:

In preview mode the link seems to work but not when published.
The control/debug button contents show the correct userId in both preview and published mode.

I am also a bit confused by the example at Velo Tutorial: Building Your Own Members Area | Help Center | Wix.com. I have relied heavily on this to set up this system.

It used the ID as a key in the Members/Update/ID reference but the ‘Connect to Data’ Button connects to the Members Item database and then links to Members (Email). I would have thought that the link should be to Members (ID) if the ID is used as the link field.

Any thoughts?

Many thanks again for the help.

Regards,

Klaus

----- Page Code below ----------
import wixUsers from ‘wix-users’;
import wixData from ‘wix-data’;
import wixLocation from ‘wix-location’;
let userId;
let userEmail;

export function profileButton_click(event, $w) {
wixLocation.to(“/Alumni-Members/MemberInfo/25ade2ce-ff56-4d3b-8979-2b6dccefae76”); // inserted kfelsche@ozemail ID - still defaults to first record in database in published mode
// wixLocation.to(“/Alumni-Members/MemberInfo/${wixUsers.currentUser.id}”); // moved inside the sub-routine
$w(“#button6”).label = wixUsers.currentUser.id; //control
}

$w.onReady(() => {
if (wixUsers.currentUser.loggedIn) {
$w(“#loginButton”).label = “Logout”;
$w(“#profileButton”).show();
$w(“#button6”).label = wixUsers.currentUser.id; //control
} else {
$w(“#loginButton”).label = “Login”;
$w(“#profileButton”).hide();
}
});

export function loginButton_click_1(event, $w) {
// user is logged in
if (wixUsers.currentUser.loggedIn) {
// log the user out
wixUsers.logout()
.then(() => {
// update buttons accordingly
$w(“#loginButton”).label = “Login”;
$w(“#profileButton”).hide();
wixLocation.to(“/Alumni-Members/MemberInfo/25ade2ce-ff56-4d3b-8979-2b6dccefae76”); // inserted kfelsche@ozemail ID
//wixLocation.to(/Alumni-Members/MemberInfo/${wixUsers.currentUser.id}); // moved inside the sub-routine
});
}
// user is logged out
else {
// 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(“Alumni_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(“Alumni_Members”, toInsert)
.catch((err) => {
console.log(err);
});
let userId = wixUsers.currentUser.id;
wixLocation.to(“/Alumni-Members/MemberInfo/25ade2ce-ff56-4d3b-8979-2b6dccefae76”); // inserted kfelsche@ozemail ID
// wixLocation.to(“/Alumni-Members/MemberInfo/${wixUsers.currentUser.id}”);
}
// update buttons accordingly
$w(“#loginButton”).label = “Logout”;
$w(“#profileButton”).show();
})
.catch((err) => {
console.log(err);
});
}
}

Done a data sync and it still goes to the wrong record. The correct user.Id is 25ade2ce-ff56-4d3b-8979-2b6dccefae76 but it goes to f8e6bfd8-78cc-4e8f-b61d-a5b02175f56f (top of the list).

Found ===> f8e6bfd8-78cc-4e8f-b61d-a5b02175f56f
…62543ab3e2ca
…672bdc3e1070
…acd6c8f669e1
…f6c77ade5b0b
…c7822e61f10f
…c709a9eeb8a8
Target ===> 25ade2ce-ff56-4d3b-8979-2b6dccefae76

The only good thing is that, after syncing the databases, both the preview and published versions produce the same outcome so my error is consistent!

export function profileButton_click(event, $w) {

$w(“#button6”).label = wixUsers.currentUser.id; //shows 25ade2ce-ff56-4d3b-8979-2b6dccefae76 wixLocation.to(/Alumni-Members/MemberInfo/${wixUsers.currentUser.id}); // ends up at f8e6bfd8-78cc-4e8f-b61d-a5b02175f56f
}

The console:

Loading the code for the site. To debug this code, open masterPage.js in Developer Tools.
Loading the code for the My Member Profile page. To debug this code, open uibqq.js in Developer Tools.
Loading the code for the site. To debug this code, open masterPage.js in Developer Tools.
Loading the code for the Alumni_Members MemberInfo (ID) page. To debug this code, open vnw52.js in Developer Tools.

When I ‘hardwire’ the userID
wixLocation.to(/Alumn-Members/MemberInfo/a1b08c5d-7295-4d77-a7e4-f6c77ade5b0b);

it still ignores it and goes back to the top of the file.

Hi Klaus,

Did you ever get this sorted out? I’m having the same issue… my dynamic pages show each indivudal member page correctly in preview, but when I go to the published version I only see the most recent entry (top row) from my database…

If you ever got your code working, I’d love any input you might have! Or if not, maybe we can sort this out together?

Thanks!
Annie

Hi Annie

No, haven’t solved this issue yet. I have been working on oher parts of the website as achieving outcomes is good for the morale.

I’m sure the fix is straight forward - once I know how! In the meantime, the consistent issues for my site are around the database pointer not going to the correct record using dnamic pages even when the wixuser is correctly identified on the original page. By the time the dynamic page is loaded the pointer is lost and the site seems to load teh latest record by default. I have checked the database and the correct URLs seem to be stored so I’m clearly not doing something right (yet).

Clearly I’d love to solve the problem as it will allow for considerable functionality I can’t expose yet.

If I crack the issue, I will certainly share my lesson with you (PS - I like your layout in the sample code).

Regards,

Klaus

Hey Klaus, any luck yet? I’m still stuck on this and my “help” seems to have abandoned me on my other posts regarding this issue :frowning:

Hi Annie
I’m on the road at the moment (Singapore at the moment) but will get back next week to have another go. I am tempted to set up another system with nothing else in it except the test data and the troublesome code. If that works then the problem might be in some code elsewhere on my site. Not sure if you’ve already tried this approach but I think that’s going to be my next step unless I get some inspiration while squeezed into economy class seats on my travels.

Of course I’ll let you know how that goes.

Regards,

Klaus

EXACT same problem. So frustrating!

Haven’t had a chance to do much on this yet. Sorry, can’t seem to find the answer (yet).

https://support.wix.com/en/article/corvid-tutorial-building-your-own-members-area