oauthSession

tcmts.registry.session.oauthSession · #ebczbpme · term · runs anywhere

A session from the OAuth library's.

import type { RegistrySession } from "#codebase/tcmts/registry/session";
import { deleteStoredSession, OAuthUserAgent } from "@atcute/oauth-browser-client";
import type { getSession } from "@atcute/oauth-browser-client";

export function oauthSession(s: Awaited<ReturnType<typeof getSession>>): RegistrySession {
  const agent = new OAuthUserAgent(s);
  const did = s.info.sub;
  return {
    did,
    fetch: (path, init) => agent.handle(path, init),
    signOut: async () => {
      try {
        await agent.signOut();
      } catch {
        deleteStoredSession(did);
      }
    },
  };
}

uses

used by