SDK Reference
Complete documentation of the Veiled JavaScript SDK
VeiledClient
Main class for interacting with the Veiled API
Constructor
new VeiledClient(config: VeiledConfig)Parameters:
apiKeyrequiredYour API key obtained from the dashboard
apiUrloptionalAPI URL (default: https://verify.veiled.id/api/v1)
localeoptionalInterface language: 'it-IT' | 'en-US' (default: 'it-IT')
debugoptionalEnable debug logging (default: false)
Methods
isVerified()
Check if the user is already verified
async isVerified(): Promise<IsVerifiedResult>Returns:
{
verified: boolean;
token?: string;
userId?: string;
}verify()
Start the age verification process
async verify(options?: VerifyOptions): Promise<VerifyResult>Options:
providerVerification provider: 'yoti' | 'namirial'
returnUrlReturn URL after verification (default: current page)
modeMode: 'redirect' | 'popup' (default: 'redirect')
onSuccessCallback called after successful verification
onErrorCallback called on error
getStatus()
Get current verification status
getStatus(): { verified: boolean; token?: string }clear()
Remove current verification (logout)
clear(): void🆕 QR Verification Methods
New QR code verification methods (v2.0+)
showQRVerification()
Show a modal with QR code for mobile verification. The method automatically handles status polling and final confirmation.
async showQRVerification(options?: QRSessionOptions): Promise<void>Options:
returnUrlReturn URL (default: current page)
onScannedCallback called when QR is scanned
onCompletedCallback called after verification completed (receives JWT token)
onErrorCallback called on error
onTimeoutCallback called if session expires
onCancelCallback called if user closes the modal
verifyDirect()
Direct verification on mobile/desktop without QR code. Automatically detects device type.
async verifyDirect(options?: { returnUrl?: string }): Promise<void>createQRSession()
Create a QR session manually (for custom implementations).
async createQRSession(returnUrl?: string): Promise<SessionCreateResult>Returns:
{
sessionId: string;
qrCodeUrl: string;
qrCodeDataUrl: string;
expiresAt: string;
}checkQRStatus()
Check the status of a QR session.
async checkQRStatus(sessionId: string): Promise<SessionStatusResult>Returns:
{
status: 'waiting_for_scan' | 'scanned' | 'pending_confirmation' | 'completed' | 'expired' | 'failed';
ready: boolean;
expiresAt: string;
}confirmQRSession()
Confirm a QR session and retrieve the JWT token.
async confirmQRSession(sessionId: string): Promise<SessionConfirmResult>Returns:
{
success: boolean;
token?: string;
userId?: string;
error?: string;
message?: string;
}handleDirectReturn()
Handle return from direct verification, extracting the token from URL.
async handleDirectReturn(): Promise<{ success: boolean; token?: string }>Examples
Basic Verification
const veiled = new Veiled.VeiledClient({
apiKey: 'pk_live_your_key'
});
const { verified } = await veiled.isVerified();
if (!verified) {
await veiled.verify();
}🆕 QR Verification (Desktop → Mobile)
const veiled = new Veiled.VeiledClient({
apiKey: 'pk_live_your_key'
});
// Mostra QR code per verifica mobile
await veiled.showQRVerification({
onScanned: () => {
console.log('📱 QR scansionato!');
},
onCompleted: (token) => {
console.log('✅ Verifica completata!', token);
unlockContent();
},
onError: (error) => {
console.error('❌ Errore:', error);
}
});🆕 Direct Verification (Mobile/Desktop)
const veiled = new Veiled.VeiledClient({
apiKey: 'pk_live_your_key'
});
// Su mobile o desktop: verifica diretta senza QR
await veiled.verifyDirect({
returnUrl: 'https://yoursite.com/callback'
});
// Sulla pagina di callback:
const { success, token } = await veiled.handleDirectReturn();
if (success) {
console.log('Token salvato!', token);
unlockContent();
}🆕 Custom QR Implementation
const veiled = new Veiled.VeiledClient({
apiKey: 'pk_live_your_key'
});
// 1. Crea sessione QR
const session = await veiled.createQRSession();
console.log('Session ID:', session.sessionId);
console.log('QR URL:', session.qrCodeUrl);
// 2. Mostra QR code nella tua UI custom
displayQRCode(session.qrCodeUrl);
// 3. Polling status
const checkStatus = setInterval(async () => {
const status = await veiled.checkQRStatus(session.sessionId);
if (status.ready) {
clearInterval(checkStatus);
enableConfirmButton();
}
if (status.status === 'expired') {
clearInterval(checkStatus);
showError('Sessione scaduta');
}
}, 3000);
// 4. Conferma quando utente clicca
confirmButton.addEventListener('click', async () => {
const result = await veiled.confirmQRSession(session.sessionId);
if (result.success) {
console.log('Token:', result.token);
unlockContent();
}
});With Callbacks
await veiled.verify({
onSuccess: (token) => {
console.log('Verificato!', token);
showProtectedContent();
},
onError: (error) => {
console.error('Errore:', error);
showErrorMessage();
}
});With Debug
const veiled = new Veiled.VeiledClient({
apiKey: 'pk_live_your_key',
debug: true // Abilita log console
});