User
A collection of methods for handling user authentication and managing profile data.
register
Create a new user with an email and password. emits the PelcroUserRegister
and PelcroUserLoaded
DOM events when the response is returned successfully.
Example
window.Pelcro.user.register({
email: "[email protected]",
password: "123456",
}, (error, response) => {
if (error) {
return console.log("error", error.message);
}
const user = response.data;
console.log(user);
})
Parameters
Parameter | Type |
---|---|
String | |
password | String |
username | String |
first_name | String |
last_name | String |
phone | String |
display_name | String |
title | String |
salutation | String |
organization | String |
metadata | Object \
|
login
Logs in a registered user with an email and password. emits the PelcroUserLoggedIn
and PelcroUserLoaded
DOM events when the response is returned successfully.
Example
window.Pelcro.user.login({
email: "[email protected]",
password: "123456",
}, (error, response) => {
if (error) {
return console.log("error", error.message);
}
const user = response.data;
console.log(user);
})
Parameters
Parameter | Type |
---|---|
String | |
password | String |
read
Returns the authenticated user's data.
Example
const user = window.Pelcro.user.read();
// full user object
console.log(user);
// user email
console.log(user.email);
// user subscriptions
console.log(user.subscriptions);
// user addresses
console.log(user.addresses);
// user ecommerce orders
console.log(user.orders);
// user metadata object
console.log(user.metadata);
idpLogin
Logs in a user using an identity provider. emits the PelcroUserLogin
and PelcroUserLoaded
DOM events when the response is returned successfully.
Example
window.Pelcro.user.idpLogin({
idp_name: "facebook",
idp_token: "abc1234",
email: "[email protected]",
first_name: "john",
last_name: "doe",
}, (error, response) => {
if (error) {
return console.log("error", error.message);
}
const user = response.data;
console.log(user);
})
Parameters
Parameter | Type |
---|---|
idp_name | String
|
idp_token | String |
first_name | String |
last_name | String |
phone | String |
display_name | String |
title | String |
salutation | String |
metadata | Object \
|
update
Update an existing user's profile. emits the PelcroUserUpdated
and PelcroUserLoaded
DOM events when the response is returned successfully.
Example
window.Pelcro.user.update({
auth_token: window.Pelcro.user.read().auth_token,
email: "[email protected]",
first_name: "John",
last_name: "Doe",
phone: "0123456",
display_name: "JohnDoe",
}, (error, response) => {
if (error) {
return console.log("error", error.message);
}
const user = response.data;
console.log(user);
})
Parameters
Parameter | Type |
---|---|
auth_token | String |
first_name | String |
last_name | String |
phone | String |
display_name | String |
title | String |
salutation | String |
organization | String |
metadata | Object \
|
convert
Convert a user without an email and password from an old provider with the old provider id. emits the PelcroUserRegister
and PelcroUserLoaded
DOM events when the response is returned successfully.
Example
window.Pelcro.user.convert({
old_provider_id: 1234,
email: "[email protected]",
password: "123456",
}, (error, response) => {
if (error) {
return console.log("error", error.message);
}
const user = response.data;
console.log(user);
})
Parameters
Parameter | Type |
---|---|
old_provider_id | number |
String | |
password | String |
first_name | String |
last_name | String |
metadata | Object \
|
logout
Logs out the currently logged-in user. emits the PelcroUserLogout
DOM events when the response is returned successfully.
Example
window.Pelcro.user.logout()
isAuthenticated
check if the current user is logged in or not.
Example
window.Pelcro.user.isAuthenticated()
uploadProfilePicture
Update a user's profile picture. emits the PelcroUserUpdated
and PelcroUserLoaded
DOM events when the response is returned successfully.
Example
window.Pelcro.user.uploadProfilePicture({
auth_token: window.Pelcro.user.read().auth_token,
image: newProfilePictureBlob,
}, (error, response) => {
if (error) {
return console.log("error", error.message);
}
const newPictureLink = response.data.profile_photo;
console.log(newPictureLink);
})
removeProfilePicture
Remove a user's profile picture. emits the PelcroUserUpdated
and PelcroUserLoaded
DOM events when the response is returned successfully.
Example
window.Pelcro.user.removeProfilePicture({
auth_token: window.Pelcro.user.read().auth_token,
}, (error, response) => {
if (error) {
return console.log("error", error.message);
}
const user = response.data;
console.log(user);
})
saveToMetaData
Save a key-value pair to user's metadata. emits the PelcroMetadataUpdated
DOM events when the response is returned successfully.
Example
window.Pelcro.user.saveToMetaData({
auth_token: window.Pelcro.user.read().auth_token,
key: "savedArticlesIds",
value: [14,15,88]
}, (error, response) => {
if (error) {
return console.log("error", error.message);
}
const userMetaData = response.data.metadata;
console.log(userMetaData);
})
hasOrdered
Check if the user ordered a specific e-commerce SKU.
Example
const skuIdToCheck = 1234
window.Pelcro.user.hasOrdered(skuIdToCheck)
isEntitledTo
Check if the user is entitled to a certain entitlement.
Example
const PremiumContentEntitlement = "premium"
const shouldShowPremiumContent = window.Pelcro.user.isEntitledTo(PremiumContentEntitlement)
resendEmailVerification
Resend the email verification message to the user's email address. Emits the PelcroUserUpdated
and PelcroUserLoaded
DOM events when the response is returned successfully.
Example
window.Pelcro.user.resendEmailVerification((error, response) => {
if (error) {
return console.log("error", error.message);
}
const user = response.data;
console.log(user);
})
verifyEmailToken
Verify the user's email using the token that was sent to their email address. Emits the PelcroUserUpdated
, PelcroEmailVerified
, and PelcroUserLoaded
DOM events when the response is returned successfully.
Example
window.Pelcro.user.verifyEmailToken({
token: "example_token_123",
}, (error, response) => {
if (error) {
return console.log("error", error.message);
}
const user = response.data;
console.log(user);
})
verifyLoginToken
Verify the passwordless token using the token in the magic link that was sent to their email address. Emits the PelcroUserLoaded
and PelcroUserUpdated
DOM events when the response is returned successfully.
Example
window.Pelcro.user.verifyLoginToken({
passwordless_token: "example_token_123",
}, (error, response) => {
if (error) {
return console.log("error", error.message);
}
const user = response.data;
console.log(user);
})
requestLoginToken
Takes a user's email to generate the magic link to be sent to the user's email.
Example
window.Pelcro.user.requestLoginToken({
email: "[email protected]",
}, (error, response) => {
if (error) {
return console.log("error", error.message);
}
const user = response.data;
console.log(user);
})
Updated about 16 hours ago