keptAccount

tcmts.atproto.keptAccount · #utmo3vaw · function · runs in the browser

uses localStorage

The account signed in on this browser, and how (SIGNED_IN), if any.

import { isDid, SIGNED_IN } from "#codebase/tcmts/atproto";
import type { Account, SignInOptions } from "#codebase/tcmts/atproto";

export function keptAccount(): (Account & SignInOptions) | undefined {
  try {
    const kept = JSON.parse(localStorage.getItem(SIGNED_IN) ?? "null") as
      | (Account & SignInOptions)
      | null;
    return kept && isDid(kept.did) ? kept : undefined;
  } catch {
    return undefined;
  }
}

uses

used by