feat: Introduce getLicense graphQL query

This commit is contained in:
Faruk AYDIN
2023-02-14 22:01:34 +01:00
parent 1847ad5622
commit 1dfb22d02e
7 changed files with 67 additions and 4 deletions

View File

@@ -0,0 +1,31 @@
import axios from 'axios';
import appConfig from '../config/app';
import memoryCache from 'memory-cache';
const CACHE_DURATION = 1000 * 60 * 60 * 24; // 24 hours in milliseconds
const checkLicense = async () => {
const licenseKey = appConfig.licenseKey;
if (!licenseKey) {
return false;
}
const url = 'https://license.automatisch.io/api/v1/licenses/verify';
const cachedResponse = memoryCache.get(url);
if (cachedResponse) {
return cachedResponse;
} else {
try {
const { data } = await axios.post(url, { licenseKey });
memoryCache.put(url, data.verified, CACHE_DURATION);
return data.verified;
} catch (error) {
return false;
}
}
};
export default checkLicense;