Connecting Profile _id to Repeater dynamic page

Hi Team,

I am working on a company health app that links the user to store health pages that the user creates. I am using a repeater that links to a dynamic page. The dynamic page displays data from the store as well as the logged in users details. but when the user clicks on the repeater and lands on the dynamic page the users details then change to another user in my user data base.

I need to get the current user id from the current logged in user. How do I go about fixing this issue?

Hi!

If you want to get the ID of the user that’s currently logged in you can use the currentUser function from the wix-users API.

If you follow the link above you will see a code example of how to get the current users information.

If this doesn’t help please send us a snippet of your code and a link to your website, so we can have a closer look.

Hope this helps!

Dara | Corvid Team

Hi Dara,

Thank you for the help. I tried it but no success. Here is the code on my dynamic page with my repeater:

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

// …
let user = wixUsers.currentUser;
let userId = user.id; // “r5cme-6fem-485j-djre-4844c49”
let isLoggedIn = user.loggedIn; // true
user.getEmail()
.then( (email) => {
let userEmail = email; // “user@something.com
} );
user.getRoles()
.then( (roles) => {
let firstRole = roles[ 0 ];
let roleName = firstRole.name; // “Role Name”
let roleDescription = firstRole.description; // “Role Description”
} );
user.getPricingPlans()
.then( (pricingPlans) => {
let firstPlan = pricingPlans[ 0 ];
let planName = firstPlan.name; // “Gold”
let startDate = firstPlan.startDate; // Wed Aug 29 2018 09:39:41 GMT-0500 (Eastern Standard Time)
let expiryDate = firstPlan.expiryDate; // Thu Nov 29 2018 08:39:41 GMT-0400 (Eastern Daylight Time)
} );

export function button19_onClick(event) {
$w( ‘#box11’ ).show();
}

export function brandsystemLogo_onClick(event) {
$w( ‘#box11’ ).hide();
}

export function closeButton_onClick(event) {
$w( ‘#box11’ ).hide();
}

export function viewHealth_onClick(event) {
let targetId = $w( “#user.id” ).getCurrentItem()._id;
wixLocation.to( ‘/stores-1/’ + targetId) //
}

Hey,

It looks like this is the code for the page that links to the dynamic page that you want to display the information. I can see you have a link to the page you mentioned displaying the information on in the code;

exportfunction viewHealth_onClick(event) {
let targetId = $w("#user.id").getCurrentItem()._id;  wixLocation.to('/stores-1/'+ targetId) // 
}

This is also not the correct syntax to use when linking to a dynamic page with wixLocation.to(). You should try using wixLocation.to(/stores/${targetId})

Can we see the code you have on page that you want to display your user information? Please also send us a link to your site.

Thanks!

Dara | Corvid Team.

Hi Dara,

I think the problem is that I am linking from a dynamic page (page 1) which is connected to my (Profile) database (this has the users unique id). On this page i have a repeater with a button that links to a unique item (Store) database:

Page 1:

Page2:

Hi Dara,
Can you help?

What do you need help with?

Hi Ahmad,

I am working on a company health app that links the user to store health pages that the user creates. I am using a repeater that links to a dynamic page. The dynamic page displays data from the store as well as the logged in users details. but when the user clicks on the repeater and lands on the dynamic page the users details then change to another user in my user data base.
I need to get the current user id from the current logged in user. How do I go about fixing this issue?

I think the problem is that I am linking from a dynamic page (page 1) which is connected to my (Profile) database (this has the users unique id). On this page i have a repeater with a button that links to a unique item (Store) database:

Page 1:

Page2:

I don’t think the user ID has anything to do in this case, each dynamic page has at least one field that builds its URL, and that field must be unique for every user and store, so you might consider changing the URL scheme to contain more fields in order to differentiate each dynamic page according to its unique fields.

For example, on the repeater, you need to get the current item that has the clicked button, get the item’s unique fields and set them up as the link of the button.

Here’s an example, we’ll need to use the repeater’s onItemReady() function, let’s say the URL is built with store ID, and the product, and assuming that this repeater displays products from different stores, more like a product gallery.

$w('#repeater').onItemReady( ($item, data) => {
    // Get the product ID.
    let productId = data._id;
    
    // Get the store identifier (ID or name), we'll go with name
    let name = data.name;
    
     // Setting up the button link.
     $item('#openProductButton').link = `/shop/${name}/${productId}`;
})

Notice that this line has to be the same as the URL scheme on your dynamic page URL.

`/shop/${name}/${productId}`

Hope that helped~!
Ahmad

Awesome, thank you Ahmad

Hi Ahmad,

I am still having issues as it does not link to the page at all. Please see my code bellow:

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

export function button19_onClick(event) {
$w( ‘#box11’ ).show();
}

export function brandsystemLogo_onClick(event) {
$w( ‘#box11’ ).hide();
}

export function closeButton_onClick(event) {
$w( ‘#box11’ ).hide();
}

$w( ‘#repeater1’ ).onItemReady( ($item, data) => {
// Get the product ID.
let ID = data._id;

// Get the store identifier (ID or name), we’ll go with name
let StoreName = data.name;

$w( ‘#viewHealth’ ).link = /Stores/${StoreName}/${ID};
})

You’re not placing the repeater’s onItemReady() function inside the dataset’s onReady() function inside the page’s onReady() function.

$w.onReady(async function () {
    $w('#dataset1').onReady(()=> {
        $w('#repeater1').onItemReady( ($item, data) => {
            // Your code here
    })
})

Also, you’re using my exact example, you need to adapt it to your code and your collections fields.