There are a few different ways to get the ID of a member. You can do it manually via the Memberstack dashboard, in the front end using a data attribute, or programmatically via our APIs. This article covers all three methods in order.
Get a Member ID using Data Attributes
1. Create a div, text element, or input on your site.
2. Give the element a data attribute of data-ms-member="id"
.
You can use this attribute to submit the id via a hidden input inside a form, to use it in your code, or to display it to a member.
View a Member's ID in the Dashboard
1. Select the member in your Memberstack Dashboard.
2. Under "Profile" the top field is the Member ID.
Get a Member ID from the Member Object
When a member is logged in, you have access to the "Member Object" in the front end. The object will look something like this (starting with the Member ID):
{
data: {
id: "mem...",
auth: {
email: "john@doe.com",
hasPassword: true,
providers: []
},
customFields: {
country: "Germany"
},
metaData: {
avatar: "photo.png"
},
permissions: ["view:basic:workouts"],
planConnections: [{
id: "con_...",
status: "ACTIVE"
planId: "pln_...",
type: "FREE",
payment: null
}],
verified: true
}
}
You can also get the id directly using this code.
window.$memberstackDom.getCurrentMember().then(({ data: member }) => {
if (member) {
let id = member.id
// do something with the id
}
})
Keywords: current user ID, userID, memberID, memberstackid, etc
Comments
0 comments
Please sign in to leave a comment.