In 2.0 of Memberstack, we are doing things a little differently. Instead of having a front-end API, we have a webflow package that includes our DOM package. This is Good news since our DOM package is more robust than our front-end API. Reading this article should show the differences between 1.0 and 2.0.

Accessing the member object

1.0 Example to access the logged in member object:

MemberStack.onReady.then(function(member) { 
  // check if member is logged in  
  member.loggedIn // returns true or false
 
  // do things with the member object
  member["email"]
  member["name"]
  member["id"] //current member id  
})

2.0 Example to access the logged in member object:

await window.$memberstackDom.getCurrentMember(member => {
// member will be logged in because they are the currentMember

	console.log(member);
// example member object
// {
//   data: {
//     id: "mem...",
//     auth: {
//       email: "john@doe.com"
//     }
//     customFields: {
//       country: "Germany"
//     },
//     metaData: {
//       avatar: "photo.png"
//     },
//     permissions: ["view:basic:workouts"],
//     planConnections: [
//       {
//         id: "con_...",
//         status: "ACTIVE"
//         planId: "pln_...",
//         type: "FREE",
//         payment: null
//       },
//     ]
//   }
// }
// to access the member object use something like member.data.id or member.data.customField.country

})

<aside> 🎮 Secret Cheat Code: Everyone on the Memberstack team uses code like: const memberstack = window.$memberstackDom This way, you don't need to constantly type “window.$memberstackDom.” If you do this, all of your DOM methods would work like memberstack.getCurrentMember().

</aside>

Updating the member object

V1 Example to update the logged in member object:

MemberStack.onReady.then(function(member) {  
// the following updateProfile is what updated the member object
    member.updateProfile({
        "first-name": "Dave",
        "last-name": "Mathews"  
    }, false)
})

V2 Example to update the logged in member object:

await window.$memberstackDom.updateMember({
// the updateMember method can update custom fields and metadata
    customFields: {
      country: "Canada"
    },
    metaData: {
      age: 24
    }
})

<aside> ⚠️ Important Info: In v2 we allow you to update the member's email and password by using an additional method (updateMemberAuth). To learn more about this please read our DOM package API docs.

</aside>

Logout a member

V1 Example to logout the current member:

MemberStack.logout()

V2 Example to logout the current member:

await window.$memberstackDom.logout()