Loyalty.lt
SDKsJavaScript

React Components

Drop-in QR login and card display components

React Components

Two components ship with the JavaScript SDK. Both handle session generation, the realtime subscription, expiry and regeneration — you supply credentials and callbacks.

npm install @loyaltylt/sdk react react-dom qrcode.react
import { QRLogin, QRCardDisplay } from '@loyaltylt/sdk/react';
import '@loyaltylt/sdk/styles';

<QRLogin />

Renders the QR code a customer scans to sign in.

<QRLogin
  config={{
    // Both values reach the browser. Only ever ship them to a terminal you control.
    apiKey: process.env.NEXT_PUBLIC_LOYALTY_KEY!,
    apiSecret: process.env.NEXT_PUBLIC_LOYALTY_SECRET!,
    locale: 'lt',
    shopId: 1,
    deviceName: 'Till 3',
  }}
  callbacks={{
    onScanned: () => setHint('Confirm on your phone'),
    onAuthenticated: ({ token, user }) => signIn(token, user),
    onExpired: () => setHint('QR code expired'),
    onCancelled: () => setHint('Login cancelled'),
    onError: (error) => console.error(error),
  }}
  showSendLink
  autoRegenerate
/>

This component sends your API secret from the browser. There is no way around it: the component opens the QR session itself. Render it only on a POS terminal you control. For a public website, open the session on your server and render the returned qr_code yourself — see Building your own.

PropTypeDescription
configQRLoginConfigapiKey, apiSecret, and optional apiUrl, locale, shopId, deviceName
callbacksQRLoginCallbacksonScanned, onAuthenticated, onCancelled, onExpired, onError
textsQRLoginTextsOverride any of the built-in strings
showSendLinkbooleanShow the "text me the app link" form
autoRegeneratebooleanGenerate a fresh session when one expires
classNamestringClass applied to the wrapper

onAuthenticated receives { token, user } — the customer's JWT and profile.

<QRCardDisplay />

The customer-facing side: renders a signed-in customer's loyalty card as a QR code for staff to scan.

<QRCardDisplay
  userToken={token}
  showUserInfo
  showPoints
  autoRefresh
  refreshInterval={30000}
  size={256}
  onError={(error) => console.error(error)}
/>
PropTypeDescription
userTokenstringThe customer's JWT (required)
cardIdnumberWhich card to show, when the customer has several
sizenumberQR code size in pixels
showUserInfobooleanShow the customer's name
showPointsbooleanShow the points balance
autoRefreshbooleanRe-fetch the card periodically
refreshIntervalnumberRefresh period in ms
textsQRCardDisplayTextsOverride any of the built-in strings
configQRCardDisplayConfigOptional apiUrl and locale
onError(error: Error) => voidCalled on failures

Localisation

Both components default to English. Pass texts to replace any string:

<QRLogin
  config={config}
  texts={{
    title: 'Prisijunkite su Loyalty.lt',
    scanInstruction: 'Nuskaitykite su Loyalty.lt programėle',
    expired: 'QR kodas nebegalioja',
    regenerate: 'Sugeneruoti naują',
  }}
/>

Building your own

Neither component is required. generateQrLogin + subscribeToQrLogin give you the same flow with your own markup — see QR Login.

On this page