pdsFetch

tcmts.atproto.pdsFetch · #oi3k3f7f · term · runs anywhere

A request to the signed-in account's PDS (/xrpc/…), as them: its tokens refreshed once if the PDS says they've expired.

import { dpopFetch, refreshSession } from "#codebase/tcmts/atproto";
import type { OAuthSession } from "#codebase/tcmts/atproto";

export async function pdsFetch(
  s: OAuthSession,
  p: string,
  init: RequestInit = {},
): Promise<Response> {
  const res = await dpopFetch(s.dpopKey, `${s.pds}${p}`, init, s.accessToken);
  if (res.status !== 401 || !(await refreshSession(s))) return res;
  return dpopFetch(s.dpopKey, `${s.pds}${p}`, init, s.accessToken);
}

uses

used by