Profile Button will not link to custom profile

I am attempting to link the profile button on my login page to a dynamic page. I thought it would be easy and I have seen plenty of examples, however my button keeps going to a static page. Next, I tried using code from this page Velo Tutorial: Building Your Own Members Area | Help Center | Wix.com

this line in particular does not work, it just goes to a jumbled mess of numbers
wixLocation.to(/dmList/${wixUsers.currentUser.id});

I would like to do a query into my database and select the current user’s Username (a custom field) and use that with the wixLocation.to() function. How in the heckin heck do I do that?

#database #dynamicpage #currentuser #customprofile

This is the full code from the tutorial that you have used, simply add your own dataset names and once you have also setup your dynamic pages it should take the logged in user to their own profile page where they can update their own profile by using the update dynamic page as shown in the tutorial.

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) { //Make sure that onclick event is on in properties
 // 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();
    } );
  }
 // 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("DatabaseName")  // Your own dataset name here
          .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("DatabaseName", toInsert) // Your own dataset name here 
            .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) { //Make sure that onclick event is on in properties
  wixLocation.to(`/DatabaseName/${wixUsers.currentUser.id}`); // Your own dataset name here 
} 

If you want to change the id to another field in your dataset then when you set your dynamic page url, simply delete the existing field they have used in the url and click on add field to use your own field choice instead from your dataset.

Then basically the url will be changed instead to username or name or whatever field you have chosen and you can adjust it as so in the page url for wix location.

Still stuck, then watch this walk through video - - YouTube

1 Like

Also note:
***We need to choose a field to add to the URL that uniquely identifies each member. Here we use each member’s automatically generated IDs to uniquely identify them. ***

With yourself wanting to use the users username instead, then you are open to having duplicate usernames as anybody can have the same username.

Then you will have to add more code to your page, also adding a data file to your backend as well, to make sure that when somebody creates a username, that the username is not already in use and is not duplicated again.

See here:

or
https://codequeen.wixsite.com/membership-dashboard
Create Member Website with Different Types of Members - Build Profile Page - YouTube (video for above tutorial)

1 Like

Oh and by the way, that jumbled mess of numbers you are referring to in your post, that is probably the user id you are seeing.

user.id  // "r5cme-6fem-485j-djre-4844c49"

https://www.wix.com/code/reference/wix-users.User.html#id

1 Like

So I am using this code, why does it still go to an invalid page? I already changed the data set names to my own, that was the easy part. But wisUsers.currentUser.id is going to a page with an invalid ID number. Each user I test it for goes to a different invalid ID number

actually it turned out not to be the user ID. I changed the extensions to use the ID field instead of the Username field. It turns out, even though I am using .id it is using the Owner field (_owner). This bug is preventing me from completing my website and no one seems to understand this