Skip to content

authenticate

The authenticate method is used to authenticate a user with the Alchemy Signer.

Usage

ts
import { signer } from "./signer";

// init the email auth flow
// NOTE: the signer will handle waiting for email auth to complete in another tab with this method
const user = await signer.authenticate({
  type: "email",
  email: "[email protected]",
  // optionally, pass in redirect params that will be appended to the magic link url for the user
  // in this example, a callback=/home param will be added to the final URL
  redirectParams: new URLSearchParams({ callback: "/home" }),
});

// OR if you have the bundle the query params

const user = await signer.authenticate({
  type: "email",
  bundle: new URLSearchParams(window.location.search).get("bundle"),
});
ts
import { AlchemySigner } from "@alchemy/aa-alchemy";

export const signer = new AlchemySigner({
  client: {
    // This is created in your dashboard under `https://dashboard.alchemy.com/settings/access-keys`
    // NOTE: it is not recommended to expose your API key on the client, instead proxy requests to your backend and set the `rpcUrl`
    // here to point to your backend.
    connection: { apiKey: "alcht_<KEY>" },
    iframeConfig: {
      // you will need to render a container with this id in your DOM
      iframeContainerId: "turnkey-iframe-container",
    },
  },
});

Returns

Promise<User> -- on success returns a User object representing the authenticated user.

Parameters

AuthParams -- an object that contains the following properties:

ts
export type AuthParams =
  | { type: "email"; email: string; redirectParams?: URLSearchParams }
  | { type: "email"; bundle: string; orgId?: string }
  | {
      type: "passkey";
      createNew: false;
    }
  | {
      type: "passkey";
      createNew: true;
      username: string;
      creationOpts?: CredentialCreationOptionOverrides;
    };