Link (button) to dynamic pages isn't working URGENTTTTT PLEASE HELP

I added a static profile where members go after they sign up. The button on the static page should redirect them to their profile account (dynamic page) that is connected to the users database. Even though I have been trying to figure it out 2 days in a row I just can’t get to a solution. Kind of walking towards a burnout. Can PLEASE somebody help me!

this is the link to my editor: ( the page that needs to redirect to the user profile = set up profile)

It tells you how to do all of that on this Wix Members Profile Page tutorial.
https://support.wix.com/en/article/corvid-tutorial-building-your-own-members-area

I already been through that for a dozen times. It does redirect in preview mode and some even redirect directly to the dynamic page but some just won’t link!

What am I doing wrong?

That member profile tutorial creates two member profile pages.

  1. Profile page that displays only the members info that you want to display.
  2. Update Profile page where users can add, edit or change any of the user inputs that you have setup.

If you follow that tutorial it should all work fine and the link to the members profile page should be.

 export function profileButton_click(event) {
   wixLocation.to(`/Members/${wixUsers.currentUser.id}`);
  }

However, note that like most member items, this should be tested in a live and published site, it should not be tested just through the preview option only, as it clearly states on the tutorial too.

Note:
The functionality for logging users in and out of your site only works fully when viewing your published site. You will not be able to fully test your member profile pages in preview mode.

Also, remember that these are member only profile and update profile pages that only the unique member can access, no other member has access to them.

I have used this tutorial as a starting point for the code for my own members only page and it works perfectly for me.

What issues are you having with the code, post it below and point where you issues are happening.

1 Like

import wixUsers from ‘wix-users’;
import wixData from ‘wix-data’;
import wixLocation from ‘wix-location’;

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

export function login_click(event) {
// user is logged in
if (wixUsers.currentUser.loggedIn) {
// log the user out
wixUsers.logout()
.then( () => {
// update buttons accordingly
$w(“#login”).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(“#login”).label = “Logout”;
$w(“#profileButton”).show();
} )
. catch ( (err) => {
console.log(err);
} );
}
}
export function profileButton_click(event) {
wixLocation.to(/Members/${wixUsers.currentUser.id});
}

I have used this one and this doesn’t respond at all. Even though I just userprofile instead of members at the export function.

And this one that stores the members but can’t redirect them since I get a 404 error message after:
import wixUsers from ‘wix-users’;
import wixLocation from ‘wix-location’;

$w.onReady( function () {
$w(‘#register’).onClick( function () {
let email = $w(‘#email’).value;
let password = $w(‘#password’).value;
wixUsers.register(email, password)
.then(() => {
wixLocation.to(/intro/{ID});
})
})
})

all my ids are identical to the code but there must be something that I can’t see. Really frustrating.

For the first one - have a look at the properties panel and make sure you have there the onClick() function.
For the last one, of course it’s not going to work and it’ll show you 404. You can’t use “{ID}”. you should put there the actual id.

1 Like

ok thank you so much for responding. the login is working but is just redirecting to the members log in page of six itself. For the last one, I connected databases to redirect but those weren’t working either. Could I use: export function profileButton_click(event) {
wixLocation.to(/userprofile/${wixUsers.currentUser.id});
}
for the second code instead of ID?

Sorry these might be dumb questions but I am pretty new to fix and figured and learned a lot of things out the past couple of days I can say but linking these dynamic pages just seems to be thing I can’t figure out.

so is it right I can’t connect a member directly to a dynamic page after logging in or registering?

Agree with J.D. about you needing to have turned on the onClick event in the properties panel for both the ‘login’ and the ‘profileButton’.

Which it does say in the code to do as well.
We add an event handler by selecting the login button and we use the Properties panel to add a handler for the onClick event.

As for the second part, are you trying to create your own custom signup lightbox as you can just do something like this.

import wixUsers from 'wix-users';
import wixWindow from 'wix-window';
import wixLocation from 'wix-location';

$w.onReady(function () {
    
    $w("#registerButton").onClick( (event) => {
        
   let email = $w("#email").value;
   let password = $w("#password").value;
   let first = $w("#firstName").value;
   let last = $w("#lastName").value;

   wixUsers.register(email, password, {
       contactInfo: {
        "firstName": $w('#firstName').value,
        "lastName": $w('#lastName').value,
       }
      } )
      .then( (result) => {
        let resultStatus = result.status;
  wixWindow.lightbox.close();
  wixLocation.to("/sign-in-status"); //Change the URL ending to whatever page you want to send the user to after they log in.
      } );     
    } );
    
});

This works perfectly and closes after registering details before moving users to signup status page, then both names will be saved in Contacts and once site member is manually approved the member details will be added to ‘members’ database.

Plus, like J.D. has said, change your ID to whatever it should be, see here for system field names and keys that should be used.
CMS (Formerly Content Manager): About Your Collection Fields | Help Center | Wix.com

Finally, as for the login part of your code, which in theory should have been the second part of your code however you adjusted it for register for some reason, should be like this.

import wixUsers from 'wix-users';
import wixData from 'wix-data';
import wixLocation from 'wix-location';

$w.onReady( () => {
if(wixUsers.currentUser.loggedIn) {
$w("#login").label = "Logout";
$w("#profileButton").show();
}
else {
$w("#login").label = "Login";
$w("#profileButton").hide();
}
} ); 

Whereas I use this on my 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.
   } ); 
}

Again, simply change the url in wixLocation.to to whatever you want yours to be.

Also, if you set up your own custom login and signup lightboxes, then you need to change the signup settings to suit, otherwise it will still show Wix own window first.
https://support.wix.com/en/article/corvid-enabling-custom-site-registration

Plus, you can send any logged in user to their own pages, see the user api reference here.
current user - https://www.wix.com/corvid/reference/wix-users.html
user id, role, price plan etc - https://www.wix.com/corvid/reference/wix-users.User.html

if you are still struggling over this, then simply watch Nayeli (Code Queen) video about it here.
https://www.youtube.com/watch?v=Orl8GJNzG5s

She has also done an updated one that looks for duplicates too here.
https://www.youtube.com/watch?v=yLCOqsVHhD0

Thank you so much! That will definitely help. Irrelevant: what kind of whiskey do you actually prefer?

One that comes not in a glass, but in a nice aged bottle instead wrapped up carefully in an old wooden box, or better still free reign of the brewery :stuck_out_tongue_winking_eye: However, most of the time it is mainly JW, Bells or F.Grouse, or if visiting Father, then it is mainly Jameson as he seems to like just that one.

Just remember that the best and proper Whisky only comes from Scotland and Ireland. The stuff that you can get that is labelled as Whiskey with a ‘e’ is American copies or some other foreign imports.