const licenseUtils = { // version 2/19/20 5:51pm hasTrialExpiredByStartDate: function hasTrialExpiredByStartDate(startDate) { const logHdr = 'licenseUtils.hasTrialExpiredByStartDate: '; log(logHdr + 'enter'); log(logHdr + 'startDate=' + startDate); const today = new Date(); // get the current UTC date and time const diffDays = licenseUtils.getDaysBetweenDates(startDate, today); // get the number of days since the start date var trialRem = (30 - diffDays); if (trialRem < 0) trialRem = 0; trialRem = Math.round(trialRem); const expired = (trialRem < 1); log(logHdr + 'expired=' + expired); log(logHdr + 'leave'); return expired; }, getDaysBetweenDates: function getDaysBetweenDates(earlyDate, lateDate) { // return the number of days between the two dates const logHdr = 'licenseUtils.getDaysBetweenDates: '; log(logHdr + 'enter'); log(logHdr + 'earlyDate=' + earlyDate); log(logHdr + 'lateDate=' + lateDate); const diffTime = lateDate.getTime() - earlyDate.getTime(); // get the time difference between the two dates const diffDays = diffTime / (1000 * 3600 * 24); // get the number of days between the two dates log(logHdr + 'diffDays=' + diffDays); log(logHdr + 'leave'); return diffDays; }, getUserAccountAsync: async function getUserAccountAsync(auth0Client) { // return a user account object or null if none is available const logHdr = 'licenseUtils.getUserAccountAsync: '; log(logHdr + 'enter'); log(logHdr + 'atc auth0Client.getUser'); const user = await auth0Client.getUser(); // get user info log(logHdr + 'bf auth0Client.getUser'); if (user === null) { // if we didn't get a user log(logHdr + 'user is NULL, so we give up and return null'); log(logHdr + 'leave'); return null; } const appMetadata = user['https://invisiblesolutionslenses.com/app-metadata']; // read the application metadata, written by the JavaScript rule stored in Auth0 if (typeof appMetadata === "undefined") { // if none log(logHdr + 'we got a user, but app-metadata is UNDEFINED, so we return null'); log(logHdr + 'leave'); return null; } // sample appMetadata //{ // "userStatus": "trial", // "startDate": "2020-02-05T13:36:51.603Z" //} const userAccount = { startDate: appMetadata.startDate, userStatus: appMetadata.userStatus }; // allocate a user account object log(logHdr + 'we got the userAccount data'); log(logHdr + 'userAccount.startDate=' + userAccount.startDate); log(logHdr + 'userAccount.userStatus=' + userAccount.userStatus); log(logHdr + 'leave'); return userAccount; } };