I use API Badges for users, to give permissions to pages.
I try to use the Badge level to hide elements on the page, try in every way to achieve the Badge level of the current user on the client monitor, and of course fail to turn the server side and go back to the back and client side, but do so. so. Do not respond to me. Empty returns.
Is there no way to get the Badge level next to the customer, and the only choice to manage another database and register the Badge holders there, and call it?
It does not respond:
https://www.wix.com/velo/reference/wix-users-backend/badges-obj/listmemberbadges
import {badges} from 'wix-users-backend';
export function listMemberBadges(memberIds) {
return badges.listMemberBadges(memberIds)
.then((memberBadges) => {
const firstBadge = memberBadges[0].badgeIds[0];
})
.catch((error) => {
console.log(error);
});
}
You need an extra return … in order to return the badge to the frontend calling code:
import {badges} from 'wix-users-backend';
export function listMemberBadges(memberIds) {
return badges.listMemberBadges(memberIds)
.then((memberBadges) => {
const firstBadge = memberBadges[0].badgeIds[0];
return firstBadge; // return the badge here
})
.catch((error) => {
console.log(error);
});
}
See the article returning in a .then() for an explanation.
This is my code and returns me undefined
Is the documentation correct?
site
let user = wixUsers.currentUser;
let userId = user.id;
const memberIds = userId;
let uzerst = await uzermezahe(memberIds)
console.log(uzerst);
backend.jsw
export async function uzermezahe(memberIds){
let res = await listMemberBadges(memberIds)
return res
}
backend.js
export function listMemberBadges(memberIds) {
return badges.listMemberBadges(memberIds)
.then((memberBadges) => {
console.log(memberBadges);
const firstBadge = memberBadges[0].badgeIds[0];
console.log(firstBadge);
return firstBadge
})
.catch((error) => {
console.log(error);
});
}
log: undefined
This is the syntax of the listMemberBadges() function:
function listMemberBadges(memberIds: Array<string>):MemberBadges
You need to make sure that you provide an array of strings to the function. Something like this:
const memberIds = [ userId ];