Converting Memberstack 1.0 Code to 2.0 Code

Article author
Josh Lopez
  • Updated

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:

<script>
window.$memberstackDom.getCurrentMember().then(({ data: member }) => {
  if (member) {
  // do logged in logic here
    // access email using: member.auth.email
    // access id using: member.id
    // access custom fields using: member.customFields["your_field_name"]
  } else {
    // do logged out logic here
  }
})
</script>

Tip → 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, all of your DOM methods would work like this:

<script>
const memberstack = window.$memberstackDom
memberstack.getCurrentMember().then(({ data: member }) => {...})
</script>

To see more details on the getCurrentMember() method, please read our DOM package API docs.

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:

<script>
const memberstack = window.$memberstackDom;

memberstack.getCurrentMember().then(async ({ data: member }) => {
  if(member) {
    await memberstack.updateMember({ 
      customFields: { name: "John", city: "NYC" }
    })
  }
})
</script>

⚠️ 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.

⚠️ 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.

Logout a member

V1 Example to log out the current member:

MemberStack.logout()

V2 Example to log out the current member:

<script>
const logout = async () => await window.$memberstackDom.logout() 
logout()
</script>

Was this article helpful?

Comments

0 comments

Please sign in to leave a comment.