QRCode.js uses a license key system to enable premium features. Activation involves validating a JSON Web Token (JWT) which contains details about your license grant. This validation happens client-side (in the browser) or server-side (in Node.js) against a public key embedded in the library.
A valid license is required to use the following premium features:
borderOptions.inner
, borderOptions.outer
, borderOptions.text
)qrInstance.validateScanning()
)QRCode.js can be used for free without a license key or premium features. In its free mode, it allows you to create full-featured, styled QR codes without premium border features or built-in scan validation. No other restrictions are applied, meaning you can still customize colors, sizes, shapes, and other styling options available in the base library.
When using the basic border features in the free version, the library will automatically add “QR-Platform” branding text in the bottom border. This branded text cannot be removed or modified without a valid license. With a premium license, you gain full control over border text and can use borders without any branding.
QRCodeJs
instancesQRCodeJs.initializeIfNeeded()
async function initializeOnLoad() {
const isActive = await QRCodeJs.initializeIfNeeded();
console.log('License active after init:', isActive);
}
localStorage
under the key QRCodeJsLicense
QRCodeJs.license('YOUR-API-KEY')
ValidationResult
with token string// Get and store the token
const result = await QRCodeJs.license('YOUR-API-KEY');
if (result.isValid) {
await storeTokenInDatabase(result.token);
}
// Later, when you need to use the token
const storedToken = await retrieveTokenFromDatabase();
await QRCodeJs.token(storedToken); // Reactivate with stored token
QRCodeJs.license()
)function(licenseKey: string): Promise<ValidationResult>
QRCodeJs.license('YOUR-LICENSE-KEY')
POST /api/get-token
)ValidationResult
objectawait QRCodeJs.license('YOUR-LICENSE-KEY');
const qrInstance = new QRCodeJs({
data: 'https://example.com',
borderOptions: { inner: true }
});
QRCodeJs.license('YOUR-LICENSE-KEY')
.then(result => {
if (result.isValid) {
console.log('License activated!');
const qrInstance = new QRCodeJs({
data: 'https://example.com',
borderOptions: { outer: true }
});
document.getElementById('qr-container').appendChild(qrInstance.element);
} else {
console.error('License activation failed.');
}
})
.catch(error => {
console.error('Error during license activation:', error);
});
QRCodeJs.token()
)function(jwtToken: string | null): Promise<ValidationResult>
QRCodeJs.token('YOUR-JWT-STRING')
QRCodeJs.token(null)
clears stored token and deactivates licenseawait QRCodeJs.token(token);
const qrInstance = new QRCodeJs({
data: 'https://example.com',
borderOptions: { outer: true }
});
const token = 'YOUR-JWT-STRING';
if (token) {
QRCodeJs.token(token)
.then(result => {
if (result.isValid) {
console.log('License activated with token!', result.license.plan);
const qrInstance = new QRCodeJs({
data: 'https://example.com',
borderOptions: { inner: true }
});
} else {
console.error('Provided token is invalid or expired.');
}
})
.catch(error => {
console.error('Error:', error);
});
}
localhost
Exception: Always permitted regardless of domains listdomains
array (e.g., ["example.com", "example.org"]
)reason: 'DOMAIN_MISMATCH'
// Token with domain restriction
{
"domains": ["example.com", "myapp.org"],
// ... other token properties
}
// On wrong domain
const result = await QRCodeJs.token(restrictedToken);
console.log(result.isValid); // false
console.log(result.reason); // 'DOMAIN_MISMATCH'
function(url: string): typeof QRCodeJs
/api/get-token
QRCodeJs.license()
QRCodeJs
class for chainingQRCodeJs.setLicenseUrl('https://my-api.com/licenses/get-token');
await QRCodeJs.license('YOUR-LICENSE-KEY');
await QRCodeJs.setLicenseUrl('/my-api/get-license').license('YOUR-LICENSE-KEY');
function(fetcherFn: (licenseKey: string) => Promise<string>): void
QRCodeJs.configureLicenseFetcher(async (key) => {
const response = await fetch('/my/custom/endpoint', {
method: 'POST',
headers: { 'Authorization': 'Bearer ' + getAuthToken() },
body: JSON.stringify({ licKey: key })
});
if (!response.ok) throw new Error('Fetch failed');
const data = await response.json();
return data.token;
});
function(): DecodedLicenseToken | null
null
const licenseDetails = QRCodeJs.getLicenseDetails();
if (licenseDetails) {
console.log('License active. Plan:', licenseDetails.plan);
console.log('Domains:', licenseDetails.domains);
console.log('Expires:', new Date(licenseDetails.exp * 1000));
} else {
console.log('License not active or expired.');
}
function(): Promise<boolean>
async function checkStoredLicenseOnLoad() {
const isActive = await QRCodeJs.initializeIfNeeded();
console.log('License active after init:', isActive);
const details = QRCodeJs.getLicenseDetails();
if (details) console.log('Plan:', details.plan);
}
ValidationResult
where isValid: false
try {
const result = await QRCodeJs.license('INVALID-KEY');
if (!result.isValid) {
console.error('Activation failed. Reason:', result.reason);
}
} catch (error) {
console.error('Network error:', error);
}
import { QRCodeJs } from '@qr-platform/qr-code.js/node';
setLicenseUrl()
license()
with async/await
async function activateLicenseNode() {
try {
QRCodeJs.setLicenseUrl('https://your-license-api.com/get-token');
const result = await QRCodeJs.license('YOUR-NODE-LICENSE-KEY');
if (result.isValid) {
console.log('Node: License activated!', result.license.plan);
const qrInstance = new QRCodeJs({
data: 'https://example.com',
borderOptions: { inner: true }
});
} else {
console.error('Node: License activation failed.');
}
} catch (error) {
console.error('Node: Error:', error);
}
}
token()
with async/await
async function activateWithTokenNode(token) {
try {
const result = await QRCodeJs.token(token);
if (result.isValid) {
console.log('Node: License activated!', result.license.plan);
const qrInstance = new QRCodeJs({
data: 'https://example.com',
borderOptions: { outer: true }
});
} else {
console.error('Node: Token invalid or expired.');
}
} catch (error) {
console.error('Node: Error:', error);
}
}
/api/get-token
POST
application/json
{
"licenseKey": "THE_USER_PROVIDED_KEY"
}
licenseKey
{
"sub": "license-12345",
"client": "acme-corp",
"plan": "enterprise",
"email": "admin@acme.com",
"domains": ["acme.com", "acme.org"],
"iat": 1712668800,
"exp": 1744204800
}
Content-Type: text/plain
) { "error": "Invalid license key" }
license()
function(licenseKey: string): Promise<ValidationResult>
token()
function(jwtToken: string | null): Promise<ValidationResult>
setLicenseUrl()
function(url: string): typeof QRCodeJs
configureLicenseFetcher()
function(fetcherFn: (licenseKey: string) => Promise<string>): void
getLicenseDetails()
function(): DecodedLicenseToken | null
initializeIfNeeded()
function(): Promise<boolean>
ValidationResult
interface ValidationResult {
isValid: boolean;
token: string | null;
license: DecodedLicenseToken | null;
reason?: LicenseReasonCode;
}
DecodedLicenseToken
interface DecodedLicenseToken {
sub: string;
client: string;
plan: string;
email?: string;
domains?: string[];
iat: number;
exp: number;
}
localStorage
(browser) or memory state (Node.js)getLicenseDetails()
for plan
and exp
.Yes, QRCode.js can be used for free without a license key. This allows you to create full-featured, styled QR codes without premium features like advanced borders or built-in scan validation. There are no other restrictions in free mode.
When using border features without a license, the library will automatically add “QR-Platform” branding text in the bottom border of your QR code. This branding cannot be removed or customized in the free version. A premium license removes this restriction, allowing you to create custom border text or remove text entirely.
No, the QR-Platform branding in the bottom border is automatically added when using border features in the free version and cannot be modified or removed. This is a limitation of the free version. Purchasing a license allows you to remove the branding and fully customize your border text.
localStorage
until expirationgetLicenseDetails()
returns null
; you’ll need to renew with license()
or token()
.
token()
works offline with a valid JWT; license()
requires internet connection.
Check getLicenseDetails().plan
to determine which features should be available.
Ensure activation was completed before QRCode instances were created. Check for errors in the console or network requests. If using a token, ensure it is valid and not expired. If you are still having issues, please contact us for support.