juspay/hyperswitch · error · Error

No user info token available

Error message

No user info token available

What it means

Thrown synchronously by the userInfo command when globalState has no 'userInfoToken'. This token is only set by a successful terminate2Fa (token_type 'user_info'), so the error means the login sequence was broken or skipped before userInfo ran.

Source

Thrown at cypress-tests/cypress/support/commands.js:6928

          }
          globalState.set("userInfoToken", userInfoToken);
        }
      } else {
        throw new Error(
          `2FA terminate call failed with status: "${response.status}" and message: "${response.body.error.message}"`
        );
      }
    });
  });
});
Cypress.Commands.add("userInfo", (globalState) => {
  // Define the necessary variables and constant
  const baseUrl = globalState.get("baseUrl");
  const userInfoToken = globalState.get("userInfoToken");
  const url = `${baseUrl}/user`;

  if (!userInfoToken) {
    throw new Error("No user info token available");
  }

  cy.request({
    method: "GET",
    url: url,
    headers: {
      Authorization: `Bearer ${userInfoToken}`,
      "Content-Type": "application/json",
    },
    failOnStatusCode: false,
  }).then((response) => {
    logRequestId(response.headers["x-request-id"]);

    cy.wrap(response).then(() => {
      if (response.status === 200) {
        expect(response.body, "merchant_id").to.have.property("merchant_id").and
          .to.not.be.empty;
        expect(response.body, "organization_id").to.have.property("org_id").and

View on GitHub (pinned to 9b8b89dc37)

Solutions

  1. Run the full chain in the before hook: cy.userLogin(globalState); cy.terminate2Fa(globalState); cy.userInfo(globalState);
  2. If login already ran, verify terminate2Fa's response token_type was 'user_info' — any other value leaves userInfoToken unset without erroring
  3. Ensure no state-reset hook wipes userInfoToken between setup and use

Example fix

// before
cy.userInfo(globalState); // userInfoToken never set
// after
if (!globalState.get('userInfoToken')) {
  cy.userLogin(globalState);
  cy.terminate2Fa(globalState);
}
cy.userInfo(globalState);
Defensive patterns

Strategy: validation

Validate before calling

// run the full login chain only when the token is absent
if (!globalState.get('userInfoToken')) {
  cy.userLogin(globalState);
  cy.terminate2Fa(globalState);
}
cy.userInfo(globalState);

Type guard

const hasUserInfoTokenInState = (globalState) =>
  typeof globalState.get('userInfoToken') === 'string' &&
  globalState.get('userInfoToken').length > 0;

Prevention

When it happens

Trigger: Calling cy.userInfo(globalState) without cy.userLogin + cy.terminate2Fa having completed; terminate2Fa returned 200 but with a different token_type so nothing was stored; state reset between specs.

Common situations: Copy-pasting only the userInfo step into a new spec; an earlier login step failing silently (e.g., token_type mismatch branch stores nothing); globalState cleared by a beforeEach/afterEach.

Related errors


AI-assisted analysis of juspay/hyperswitch@9b8b89dc37 (2026-08-16). Data as JSON: /api/errors/df6eefac70476dde. Report an issue: GitHub.