startSignIn

tcmts.hub.session.startSignIn · #h26vsk5l · term · runs in the browser

uses sessionStorage

Send the browser to sign in as handle; it comes back to the hub's home, which finishes it (finishSignIn).

import { COMING_BACK, configure, HUB_SCOPE } from "#codebase/tcmts/hub/session";
import { createAuthorizationUrl } from "@atcute/oauth-browser-client";

export async function startSignIn(handle: string): Promise<void> {
  await configure();
  sessionStorage.setItem(COMING_BACK, location.pathname + location.search);
  const url = await createAuthorizationUrl({
    target: {
      type: "account",
      identifier: handle.trim().replace(/^@/, "") as `${string}.${string}`,
    },
    scope: HUB_SCOPE,
  });
  // (the library keeps what it needs in local storage: let it be written before leaving)
  await new Promise((r) => setTimeout(r, 200));
  location.assign(url);
}

uses

used by