I created a custom log in page using this link https://support.wix.com/en/article/wix-code-tutorial-building-your-own-members-area
This line of code bellow returns a user id that is different than the ID's in my data set. As we know, ID's are locked in data sets, so it can't be changed (at least I can't/haven't). Additionally, it consistently returns the same incorrect ID based on which ever test account I attempt to use. What is going on? (dmList is the name of my dataset)
wixLocation.to(`/dmList/${wixUsers.currentUser.id}`);
after doing some snooping around I found one of the links goes being used for currentUser.id is actually the Owner number. Still doesn't help me too much as I can't use the owner number as a field to direct to my dynamic user page
#dataset #query #customloginpage #wixUsers #wixcode #customprofile #dynamicpage
Plus if you want to use that as a custom login page, then you are better off doing what I have done with the page and adding a custom login lightbox to it too.
As currently, just using that code will log members in, however the page code won't work as it needs to be refreshed for it to kick in and work.
Just simply create a custom login lightbox and change your member signup settings to custom and use this code on your lightbox.
import wixUsers from 'wix-users'; import wixLocation from 'wix-location'; import wixWindow from 'wix-window'; $w.onReady(function () { $w("#forgotPassword").onClick( (event) => { //wixWindow.lightbox.close() wixUsers.promptForgotPassword() .then( ( ) => { // } ) .catch( (err) => { let errorMsg = err; //"The user closed the forgot password dialog" }); }); }); export function loginButton_onclick(event) { let email = $w("#email").value; let password = $w("#password").value; wixUsers.login(email, password) .then( () => { console.log("User is logged in"); wixWindow.lightbox.close(); wixLocation.to(wixLocation.url); //This reloads the same page and allows code to show hidden member parts. } ) .catch( (err) => { console.log(err); $w("#errorMessage").expand(); // You can delete this line if you are not going to add an error message. Use a regular text element set to 'collapse on load' from the Properties Panel. } ); }
i used that code myself and changed it for my own members page and everything works fine.
// For full API documentation, including code examples, visit http://wix.to/94BuAAs $w.onReady(function () { //TODO: write your page related code here... }); 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("#membersareaonlystrip").expand(); $w("#whitegapforfooter").hide(); } else { $w("#loginbutton").label = "Login"; $w("#membersareaonlystrip").collapse(); $w("#whitegapforfooter ").show(); } } ); export function loginbutton_onclick(event) { // user is logged in if(wixUsers.currentUser.loggedIn) { // log the user out wixUsers.logout() .then( () => { // update buttons accordingly $w("#loginbutton").label = "Login"; $w("#membersareaonlystrip").collapse(); $w("#whitegapforfooter ").show(); } ); } // user is logged out else { let userId; let userEmail; // prompt the user to log in wixUsers.promptLogin( {"mode": "signup"} ) .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("#membersareaonlystrip").expand(); $w("#whitegapforfooter").hide(); } ) .catch( (err) => { console.log(err); } ); } } export function profilebutton_onclick(event) { wixLocation.to(`/Members/${wixUsers.currentUser.id}`); } export function entermembersbutton_onclick(event) { wixLocation.to(`/members-area`); } export function myaccountbutton_onclick(event) { wixLocation.to(`/account/my-account`); } export function websiteupdatebutton_onclick(event) { wixLocation.to(`/website-update`); }
The (user) ID field that is used is in all your datasets, it is just set as hidden when you create a dataset, if you want to see it then you need to make it visible in your dataset.
ID (_id)
Description: The member ID that was created by the server. This is a system field and is hidden by default. Type: Text Can connect to data: Yes Can use in dynamic page URL: Yes Read-only: Yes
Plus whatever ID Wix gives a user, it should stay the same throughout the datasets and not change.
I've just checked my two datasets of mine, my Members dataset which I use for my own Members Profile page and my PrivateMembersData dataset and all the ID fields have the same ID for myself.
PrivateMembersData: My ID - XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX
Members:
ID: XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX
Members ID: /Members/XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX
Members Update ID: /Members/Update/XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX
As you can see from the tutorial the export function takes you to the users own member profile page
export function profileButton_click(event) { wixLocation.to(`/Members/${wixUsers.currentUser.id}`); }
If you wanted the user to go straight to their user member profile update page then it would be
export function profileButton_click(event) { wixLocation.to(`/Members/Update/${wixUsers.currentUser.id}`); }