Use browser QR login and server-side assertion verification.
A Next.js app needs a passwordless account system keyed by U-net scoped IDs.
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 }),
});
}
import { verifyLoginAssertion } from '@union-networks/server';
export async function POST(request: Request) {
const { assertionJws } = await request.json();
const claims = verifyLoginAssertion(assertionJws, {
secret: process.env.UNET_WEB_LOGIN_ASSERTION_SECRET!,
serviceId: 'example-shop',
});
// Store claims.scopedUserId as the account id for your service.
await createSession({ scopedUserId: claims.scopedUserId });
return Response.json({ ok: true });
}