How to prevent users from logging in when their account is inactive/terminated in bigcommerce b2b edition?

22 Views Asked by At

The code below should prevent users with inactive or terminated accounts from logging in on the site, but it's not doing that.

if (isB2BUser) {
    displayApprovalRequests(b3RoleId, b3CompanyId)
    fetch(`https://api.bundleb2b.net/api/v2/companies/${b3CompanyId}`,
    { headers: { 'authToken': b3Token } })
    .then(resp => {
        return resp.json()
    })
    .then(json => {
        const statement = json.data.extraFields.find(e=>e.fieldName=='Account Statement')
        const parsedStatement = statement && statement.fieldValue ? JSON.parse(statement.fieldValue) : {};
        const terms = (parsedStatement["Terms"] ?? "").toLowerCase()

        if (terms.includes('inactive') || terms.includes('terminated')) {
            const modal = alertModal();
            removeOpenOnModal()

            modal.close = () => { window.location.href = '/login.php?action=logout' };
            modal.open();
            modal.updateContent(`<div><strong>Your account has been placed on hold.</strong></div>`);

            disableModalClose()
        }
    })
    .catch(err => {
        console.error(err)
    })
}
0

There are 0 best solutions below