I have created a collection called “Ranking” and unfortunately I am a newbie to Code. I need to code a filter that get the username for the logged in member and then looks up the dataset “Title” of my collection where I have added the names of members. If the username matches a name in the “Title” one or more images will be shown in a list on my page.
Unfortunately I do not know how get the username and how to filter it against the dataset “Title” in my collection. Can somebody help me out please?
The owner filter does not work because the data is added by myself only not the members into the collection.
What I need is: Look up the data of the logged in member, get his username, go to collection “Ranking”, filter the username against the dataset “Title” (like Title is username), filter end and images for the member will be shown in a list on my page that is already created.
Any Ideas? Thank you so much.
Michael
Hello Michael,
You can use the WixUsers API located here to get the current users information.
To filter a dataset follow the documentation provided here: Dataset - Velo API Reference - Wix.com
If you are still running into problems after reading and trying out the API , reply with your code here.
Goodluck,
Majd
Thank you. As I can see I have only the option to use the User ID or e-mail for my collection to identify the user. There is no username, right? The ID is a string and is it hidden? I do not see how I can identify the user for my purpose.
In the collection are images that will be different for each user. How can I filter them to the correct user if I have no username?
I am sorry but i am a newbie in Code.
Michael
You can view hidden fields like so:
In your case, when a user logs in, you want to try to find there user id in your database. If it is not found, you should add the new user id to the database, maybe along with the email. Then you can go in and add the pictures to each users. Then make that database into a dynamic collection with a page for each item in that database and you should be good.
If you are looking for users to upload profile pictures to their accounts, Wix Members App does this already and comes ready to use. Check it out here: Wix Editor: Creating Members Only Pages | Help Center | Wix.com
Goodluck!
Majd
Majd - Thank you. The only User id that is in my collection database is my own since I fill in the data. There is no other database in my account that would show the user id or the new user id. If I had a database where I could find all user id’s then I could add them into my collection ranking and could filter by owner is logged in.
Michael
The ID is always different but the owner id is always the same and connected to the member. Where do i find the owner id’s of my members?
Michael
Hello
It would look something like this:
import wixUsers from 'wix-users';
let user = wixUsers.currentUser;
//Here is the user id
let userId = user.id;
let userEmail = user.
toInsert = {
'id': userID
}
//We insert user id into the collection
wixData.insert('YourCollection', toInsert)
.then((response) => {
console.log('Inserted')
})
Before we insert it however we should check to see if it is already in the database. if it is we dont add it again.
I would recommend checking out the Members Area App provided by Wix.
Goodluck
Majd