0

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 Answers0