remix-auth - v5.0.0
    Preparing search index...

    Class Authenticator<StrategyRecord>

    The Authenticator class is the main entry point for Remix Auth.

    It manages authentication strategies and provides methods to authenticate requests. Each strategy is registered with a name, which is used to identify it during the authentication process.

    import { Authenticator } from "remix-auth";
    import { FormStrategy } from "remix-auth/form";

    // Create an instance of the authenticator
    const authenticator = new Authenticator({
    strategies: {
    login: new FormStrategy(async ({ form }) => {
    // Implement your authentication logic here
    return findUserByCredentials(form);
    }),
    },
    });

    let sessionData = await authenticator.authenticate("login", request);

    Type Parameters

    • StrategyRecord extends Record<string, Strategy<any, any>>

      A record of strategies where the key is the strategy name and the value is the strategy instance

    Index

    Constructors

    Accessors

    Methods

    Constructors

    Accessors

    • get strategies(): Readonly<
          { [K in keyof StrategyRecord]: Omit<StrategyRecord[K], "authenticate"> },
      >

      Retrieves a readonly record of all registered strategies. Useful if the strategy exposes additional methods.

      The public type omits authenticate so callers go through Authenticator.authenticate. Runtime instances still expose the method on the strategy prototype.

      Returns Readonly<
          { [K in keyof StrategyRecord]: Omit<StrategyRecord[K], "authenticate"> },
      >

      let loginStrategy = auth.strategies.login;
      

    Methods

    • Authenticates a request using the specified strategy.

      This method delegates the authentication process to the named strategy and returns the authenticated user data if successful.

      Type Parameters

      • StrategyName extends string | number | symbol

      Parameters

      Returns Promise<StrategyRecord[StrategyName] extends Strategy<SD, any> ? SD : never>

      Promise resolving to the session data

      async function action({ request }: ActionFunctionArgs) {
      try {
      const sessionData = await auth.authenticate("login", request);
      // User is authenticated, do something with the session data
      return redirect("/dashboard");
      } catch (error) {
      // Handle authentication error
      return json({ error: error.message });
      }
      }