U-net Docs
0.2.0-alpha.3

@union-networks/web-login

High-level browser helpers for Sign in with U-net.

bashInstall
npm install @union-networks/web-login@alpha

When to use it

Exports

createLoginSessionpollLoginSessionrenderLoginQrPayloadisApprovedLoginResultresolveWebLoginServicecreateServiceSession

Examples

tsLogin QR
import {
  createLoginSession,
  isApprovedLoginResult,
  pollLoginSession,
  renderLoginQrPayload,
} from '@union-networks/web-login';

const session = await createLoginSession(
  {
    serviceId: 'example-shop',
    origin: window.location.origin,
    expiresInSeconds: 120,
  },
  { issuerBaseUrl: 'https://issuer.egress.live' },
);

renderQr(renderLoginQrPayload(session));

const result = await pollLoginSession(session.sessionId, {
  issuerBaseUrl: 'https://issuer.egress.live',
  intervalMs: 1500,
  timeoutMs: 120000,
});

if (isApprovedLoginResult(result)) {
  await fetch('/api/unet/session', {
    method: 'POST',
    headers: { 'content-type': 'application/json' },
    body: JSON.stringify({ assertionJws: result.assertionJws }),
  });
}