takeSignIn

tcmts.atproto.takeSignIn · #e6ndwykd · function · runs on the server

uses tcmts.atproto.serviceAudiences, which uses process

Sign the caller in to the app's server as the account a service-auth token is from: checked for this server (#ga5isctt) and SIGN_IN_LXM, then kept in the caller's server session for 30 days (account says who). Who it is.

import { accountOf, serviceAudiences, SIGN_IN_LXM, verifyServiceAuth } from "#codebase/tcmts/atproto";
import type { Account } from "#codebase/tcmts/atproto";
import { HttpError, session, setSession } from "#codebase/tcmts/atproto/lib/server";

export async function takeSignIn(jwt: string): Promise<Account> {
  const audiences = serviceAudiences();
  if (!audiences.length)
    throw new HttpError(
      500,
      "This server doesn't know its own address, so it can't check a sign-in: set ATPROTO_SERVICE_URL.",
    );
  let did: string;
  try {
    did = await verifyServiceAuth(jwt, { audiences, lxm: SIGN_IN_LXM });
  } catch (e) {
    throw new HttpError(401, `Signing in didn't check: ${(e as Error).message}`);
  }
  const who = await accountOf(did);
  setSession({ ...session(), atproto: who });
  return who;
}

uses

used by