v.1.0.0. initial push of license-lib

This commit is contained in:
2025-03-19 09:37:30 -05:00
commit b22a1c973c
20 changed files with 433 additions and 0 deletions

31
react/LicenseProvider.js Normal file
View File

@ -0,0 +1,31 @@
// react/LicenseProvider.js
import React, { createContext, useState, useEffect } from 'react';
import { activateLicense } from '../client/validate';
import { cacheLicenseData, getCachedLicenseData, isLicenseCacheValid } from '../client/offline';
export const LicenseContext = createContext();
export const LicenseProvider = ({ userId, licenseKey, children }) => {
const [isLicensed, setIsLicensed] = useState(false);
useEffect(() => {
const checkLicense = async () => {
if (navigator.onLine) {
const valid = await activateLicense(userId, licenseKey);
setIsLicensed(valid);
if (valid) cacheLicenseData({ userId, licenseKey });
} else {
setIsLicensed(isLicenseCacheValid());
}
};
checkLicense();
}, [userId, licenseKey]);
return (
<LicenseContext.Provider value={{ isLicensed }}>
{children}
</LicenseContext.Provider>
);
};

8
react/useLicense.js Normal file
View File

@ -0,0 +1,8 @@
// react/useLicense.js
import { useContext } from 'react';
import { LicenseContext } from './LicenseProvider';
const useLicense = () => useContext(LicenseContext);
export default useLicense;