How to link a button to a "MyProfile " page?

I would like to connect a button to the “my profile” page of the user who is logged in at that moment.

The problem is that the “Profile” link is dynamic:

www. dominio .com/profile/ {userName} /my_profile

How can I enter that dynamic value in the URL (in between)?

Thank you very much!!

Hey there,

You can accomplish this using the built in members collection. Each member has a field in that collection called the slug, which is much faster to find than the animal. That slug field corresponds to the {userName} you mentioned above.

A small snippet of code that might help you get started is below. The steps are:

  1. Query the collection for that specific user

  2. Retrieve the slug field

  3. Create the URL.

//... code can be on any page or in masterPage.js. 

import wixUsers from 'wix-users';
import wixData from 'wix-data';
$w.onReady(async ()=>{
//...
//1. Query collection.
const userRecordFromDB = await wixData.get('Members/PrivateMembersData',wixUsers.currentUser.id,{suppressAuth:true});

//2. Get the slug field
const slug  = userRecordFromDB.slug;

//3. Create your url. You can use the exact code below
const profilePageURL = `www.dominio.com/profile/${userName}/my_profile`; 

//Do what you wish with the URL.
});

N.B. from an architecture and performance POV, I’d suggest you cache the slug as soon as they log in using Session Storage, to avoid querying the DB many times, every time the desired page loads. It’s unlikely their slug would change.

Also, keep in mind that the final page for the profile will be controlled by the settings you adjust in your members page, so if you change it from ‘profile’ to ‘account’, for example, remember to update it later on.

Hope this helps
Chris

Thank you very much for your help! :grinning: