One possibility to get current logged in user…
import { currentMember } from 'wix-members';
// ...
// Sample options value:
// {
// fieldsets: [ 'FULL' ]
// }
currentMember.getMember(options)
.then((member) => {
const id = member._id;
const fullName = `${member.contactDetails.firstName} ${member.contactDetails.lastName}`;
return member;
})
.catch((error) => {
console.error(error);
});
/* Returned member object:
* {
* "_id": "f32cbc51-a331-442b-86c2-2c664613e8b9",
* "_createdDate": "2021-08-02T23:14:42Z",
* "_updatedDate": "2021-08-02T23:14:58.345Z",
* "lastLoginDate": "2021-08-12T19:46:33Z",
* "loginEmail": "claude.morales@example.com",
* "contactId": "f32cbc51-a331-442b-86c2-2c664613e8b9",
* "status": "APPROVED",
* "privacyStatus": "PRIVATE",
* "activityStatus": "ACTIVE",
* "profile": {
* "nickname": "Claude Morales",
* "slug": "claudemorales",
* "profilePhoto": {
* "_id": "a27d24_0dd318~mv2.jpg",
* "url": "//static.wixstatic.com/media/a27d24_0dd318~mv2.jpg",
* "height": 256,
* "width": 256,
* "offsetX": 1,
* "offsetY": 1
* },
* "coverPhoto": {
* "_id": "myimage.jpg",
* "url": "https://example.com/myimage.jpg",
* "height": 1080,
* "width": 1920,
* "offsetX": 1,
* "offsetY": 1
* },
* "title": "Awesome title"
* },
* "contactDetails": {
* "firstName": "Claude",
* "lastName": "Morales",
* "phones": [
* "0747-769-460"
* ],
* "emails": [
* "claude.morales@example.com"
* ],
* "addresses": [
* {
* "country": "GB"
* },
* {
* "_id": "f0f4d905-488d-44db-9080-fc29078cfad5",
* "addressLine": "9373 Park Avenue",
* "addressLine2": "Berkshire",
* "city": "Ely",
* "subdivision": "GB-ENG",
* "country": "GB",
* "postalCode": "PD50 8EU"
* }
* ],
* "customFields": {}
* }
* }
*/
Another one, but OLD and DEPRICATED version to get current user…
import wixUsers from 'wix-users';
2
3// ...
4
5let user = wixUsers.currentUser;
6
7let userId = user.id; // "r5cme-6fem-485j-djre-4844c49"
8let isLoggedIn = user.loggedIn; // true
9
10user.getEmail()
11 .then( (email) => {
12 let userEmail = email; // "user@something.com"
13 } );
14
15user.getRoles()
16 .then( (roles) => {
17 let firstRole = roles[0];
18 let roleName = firstRole.name; // "Role Name"
19 let roleDescription = firstRole.description; // "Role Description"
20 } );
Some more stuff about all this, can be found here…