Browser

Browser Quick Start

Client-side snippets showing pairing using Quick Connect and storing a device token with `DeviceSession`.

quickconnect.ts — Initiate & Join

import { initiateQuickConnect, joinQuickConnect } from '@epheme/core/browser/quickConnectClient';

async function pair() {
  const base = 'https://hub.example.com';
  const resp = await initiateQuickConnect(base);
  console.log('Enter this code on the other device:', resp.code);
  // After the other device uses the code, join it:
  const join = await joinQuickConnect(base, resp.code);
  console.log('Paired session id:', join.id);
}
import { DeviceSession } from '@epheme/core/browser/deviceSession';

const session = new DeviceSession();
// after obtaining token from server
session.setToken('DEVICE_JWT');
const res = await session.fetchWithAuth('/api/protected');
console.log(await res.json());