Customer Portal Link
To initialize the Recharge JavaScript SDK you will need to do it within the root of your theme (wherever the <head />
element is located). Generally this is located in a file called theme.liquid
. For this example you will need to initialize your client with a Recharge storefrontAccessToken
.
Example
This example will show you how to implement a link to your customer portal.
Create a new file within the theme editor called portal-link.liquid
. Then render that snippet on any page you would like. Note that this file needs to be a snippet not a section or page.
Liquid file where you want to render the customer portal link.
<div>{%- render 'portal-link' -%}</div>
portal-link.liquid
<portal-link></portal-link>
<script>
class PortalLink extends HTMLElement {
constructor() {
super();
this.attachShadow({ mode: 'open' });
this.renderLink();
}
async login() {
this.session = await recharge.auth.loginShopifyAppProxy();
}
async fetchPortalAccess() {
this.portalAccess = await recharge.customer.getCustomerPortalAccess(this.session);
}
async renderLink() {
await this.login();
await this.fetchPortalAccess();
this.shadowRoot.innerHTML = `
`;
}
}
customElements.define('portal-link', PortalLink);
</script>