Check whether a session is signed in and run scripted sign-in logic when it is not.
librettoAuthenticate()librettoAuthenticate is the runtime helper for workflows that combine an auth profile with scripted sign-in logic.1234async function librettoAuthenticate( ctx: LibrettoWorkflowContext, options: LibrettoAuthenticateOptions, ): Promise<{ usedProfile: boolean }>;
path isSignedIn(ctx: LibrettoWorkflowContext) => Promise<boolean> | booleanrequiredtrue
only when the workflow can safely continue.path signIn(ctx: LibrettoWorkflowContext, credentials: Record<string, string>) => Promise<void> | voidrequiredisSignedIn returns false.path credentialsRecord<string, unknown>signIn. In workflows, pass
input.credentials from declared workflow credentials.path envPrefixstringcredentials is omitted.
Workflow code should normally pass input.credentials instead.usedProfilebooleantrue when the initial isSignedIn check passed, meaning the saved profile
was already signed in. false when Libretto ran the signIn step.123456789101112131415161718192021222324252627282930import { librettoAuthenticate, workflow } from "libretto"; export default workflow("portalReport", { startUrl: "https://portal.example.com", credentials: ["username", "password"], authProfile: { name: "portal", refresh: true, }, async handler(ctx, input) { const { page } = ctx; await librettoAuthenticate(ctx, { credentials: input.credentials, isSignedIn: async ({ page }) => await page .getByRole("button", { name: /account|sign out/i }) .isVisible() .catch(() => false), signIn: async ({ page }, credentials) => { await page.goto("https://portal.example.com/login"); await page.getByLabel("Email").fill(credentials.username); await page.getByLabel("Password").fill(credentials.password); await page.getByRole("button", { name: /log in/i }).click(); }, }); // Continue with authenticated workflow steps. }, });
signIn runs, librettoAuthenticate calls isSignedIn again. If the session is still not signed in, it throws an error instead of letting the workflow continue in a logged-out state.librettoAuthenticate with authProfile: { name, refresh: true } when
a successful sign-in should update the profile for future runs.