Since the wix-members-backend isn’t working that well, how would I use wixUsers to get the currently logged in member’s login email? Thanks in advance!
The issue with wix-members has been fixed. And imho you should proceed working with it and not with the deprecated wix-users-backend.
J.D. → fixed → like completely fixed?
I mean the currentMember.getMember(). Has that been fixed?
@russian-dima I thought so, but maybe I’m wrong (I haven’t tried).
Can you check?
@solsticematholympiad
Meanwhile - for the deprecated module, you can try:
import wixUsers from 'wix-users-backend';
export function getUserEmail(){
return wixUsers.currentUser.getEmail();
}
@jonatandor35
I will test it on my Login-System tomorrow and give some feedback, stay tuned…
@jonatandor35 Thanks so much!
@solsticematholympiad
I tested the API on both ends (front & backend) and everything seemed to work just fine…
Frontend-Results:
Test-Code-Frontend:
//wix-members-api-frontend---------------------------------------------------------------
let currentMember = wixMembers.currentMember; console.log("Current-Member: ", currentMember);
let xxx = wixMembers.authentication; console.log(xxx)
let member = await currentMember.getMember(); console.log("Member: ", member);
let roles = await currentMember.getRoles(); console.log("Roles: ", roles);
console.log("------------------------------------------------")
//wix-members-api-frontend---------------------------------------------------------------
Backend-Results:
Test-Code-Backend:
export async function getMemData() {
let roleID = "398fcea8-e71d-42cd-b60a-4907f6910b8f"; //VIP
let memberID = "dcbea489-ea9f-41e7-9552-a241161739d6";
let currentMember = await wixMembersBackend.currentMember;
let authorization = await wixMembersBackend.authorization;
let authentication = await wixMembersBackend.authentication;
let BADGES = await wixMembersBackend.badges;
let members = await wixMembersBackend.members;
let member = await currentMember.getMember();
let roles = await currentMember.getRoles();
let badges = await BADGES.listMemberBadges([memberID]);
let member2 = await members.getMember(memberID);
authorization.assignRole(roleID,memberID);
return ({member:member, roles:roles, authorization:authorization, badges:badges, member2:member2});
}
But wait!!! Where is the e-mail ?
To solve your Problem —>> add OPTIONS (FULL) → this will activate the return of the FULL-CONTACT-DETAILS…
export async function getMemData() {
let options = {
fieldsets: [ 'FULL' ]
}
let roleID = "398fcea8-e71d-42cd-b60a-4907f6910b8f"; //VIP
let memberID = "dcbea489-ea9f-41e7-9552-a241161739d6";
let currentMember = await wixMembersBackend.currentMember;
let authorization = await wixMembersBackend.authorization;
let authentication = await wixMembersBackend.authentication;
let BADGES = await wixMembersBackend.badges;
let members = await wixMembersBackend.members;
let member = await currentMember.getMember(options);
let Email = await member.loginEmail;
let ContactDetails = await member.contactDetails;
let roles = await currentMember.getRoles();
let badges = await BADGES.listMemberBadges([memberID]);
let member2 = await members.getMember(memberID);
authorization.assignRole(roleID,memberID);
return ({member:member, contactDetails:ContactDetails, roles:roles, authorization:authorization, badges:badges, email:Email, member2:member2});
}
Unless you did not activate the → FULL ← member-details-option, you won’t get all user-/member-details!!!
After you added the → options ← you also get more INFORMATION about the current user.
So it seems that everything is working just well and the usage of the depricated wixUsers-API is not needed anymore.
BTW: Also the BADGE-ASSIGNING was woking well!
Hi Dima, is there a solution of this issue? Same problem - users have to reload a page then it woks fine.
I will take a look at it later once again. Perhaps it would also make sense, if someone could inspect it directly on your setup, or on somes-else setup (where it do not work).
I will give you feedback later. Currently working on another project.
To be continued…