Hi!
I want my code to check if you have a badge, and if so, a button will appear.
My badges are in rows in a database and the users with the badge have their id listed under the members column.
How do I make my code check if the active user’s id is under a badge row?
Hello,
try to work with this one… to solve the first part of your issue…
import wixUsers from'wix-users';
function get_UserData() {
let user = wixUsers.currentUser;
let userId = user.id; // "r5cme-6fem-485j-djre-4844c49"
let isLoggedIn = user.loggedIn; // true
console.log(user)
console.log(userId)
console.log("isLoggedIn = " + isLoggedIn )
user.getEmail()
.then( (email) => {
let userEmail = email; // "user@something.com"
console.log(userEmail)
} );
user.getRoles()
.then( (roles) => {
let firstRole = roles[0];
let roleName = firstRole.name; // "Role Name"
let roleDescription = firstRole.description; // "Role Description"
console.log (roles)
console.log (firstRole)
console.log (roleName)
console.log (roleDescription)
} );
}
Take a look into your CONSOLE and at the RESULTS.
It could be that you have to modify the CODE a little bit, i did not test it.
Hi!! I had to get rid of
function get_UserData() {
because it was not causing the console logs to not show up.
And for user.getRoles(), it says I’m now allowed to use it in preview mode. Is there a preview friendly alternative or should I wait to publish it and then use user.getRoles?
@amelia3308
This is tested and works (also in PREVIEW-MODE).
import wixUsers from'wix-users';
$w.onReady(function () {get_UserData() })
function get_UserData() {
let user = wixUsers.currentUser;
let userId = user.id; // "r5cme-6fem-485j-djre-4844c49"
let isLoggedIn = user.loggedIn; // true
console.log(user)
console.log(userId)
console.log("isLoggedIn = " + isLoggedIn )
user.getEmail()
.then( (email) => {
let userEmail = email; // "user@something.com"
console.log(userEmail)
});
user.getRoles()
.then( (roles) => {
let firstRole = roles[0];
let roleName = firstRole.name; // "Role Name"
let roleDescription = firstRole.description; // "Role Description"
console.log (roles)
console.log (firstRole)
console.log (roleName)
console.log (roleDescription)
});
}
