Skip to main content

Core Components

HawcxInitializer

Initializes the Hawcx Smart Connect SDK. This must be called before any other SDK methods.Parameters:
  • apiKey (string): Your Hawcx API Key.
  • apiEndpoint (string, optional): The base URL for the Hawcx API. Defaults to the production endpoint if not provided.
Returns: Promise → HawcxAuthInstance
HawcxAuthInstance
object
An instance of the Hawcx Smart Connect SDK, with methods like authenticate and verify.
Gets current SDK instanceReturns: SDK instance

Smart Connect Authentication Methods

Initiates the Smart Connect authentication process for a user with the given email address. This revolutionary method intelligently handles both new user registrations and existing user sign-ins through a single, unified interface. Smart Connect automatically determines the user context and whether OTP verification is needed.Parameters:
  • email (string): The user’s email address.
Returns: Promise → AuthenticationResponse
AuthenticationResponse
object
The response object from the Smart Connect authentication attempt.
Verifies a One-Time Password (OTP) that was sent to the user after Smart Connect determined verification was needed (when authenticate returned "OTP_NEEDED" status).Parameters:
  • params (object): An object containing the verification details.
Returns: Promise → VerificationResponse
VerificationResponse
object
The response object from the OTP verification attempt.
Initiates a QR code-based login flow powered by Smart Connect. This method enables seamless cross-platform authentication where users can scan a QR code with their registered mobile app. The function manages the complete lifecycle of the QR session with intelligent authentication handling.Parameters:
  • callbacks (object): An object containing the callback functions and configuration for the Smart Connect QR flow.
Returns: Promise<void>
Promise<void>
Promise
This method returns a Promise that resolves when the Smart Connect QR flow has been initiated. The results of the operation (PIN, success, or error) are delivered through the callback functions.

Response Object

All Smart Connect authentication methods return an AuthResponse object:
{
  detail: string,         // Human-readable result message
  status: string|null,  // Operation status, e.g., "SUCCESS", "OTP_NEEDED", "INVALID_EMAIL"
  data: object|null        // Additional operation data
}

Status Codes

General & Initialization

CodeDescription
SUCCESSThe operation was successful.
NOT_INITIALIZEDSDK has not been initialized. HawcxInitializer.init() must be called first.
INITIALIZATION_FAILEDThe SDK failed to initialize, possibly due to an invalid API key or network issue.
CLIENT_ERRORAn unexpected client-side error occurred during an operation.

Smart Connect Email & OTP Flow

CodeDescription
INVALID_EMAILThe provided email address is not in a valid format.
USER_NOT_FOUNDThe email address is not registered in the system.
INVALID_OTPThe One-Time Password provided by the user is incorrect.
VERIFICATION_FAILEDThe OTP verification process failed for a reason other than an invalid OTP.
MISSING_USERNAMEThe userid (email) was not provided to the function requiring it.

Smart Connect QR Code Flow

CodeDescription
QR_TIMEOUTThe QR code was not scanned within the allowed time limit (default 2 minutes).
QR_CREATE_FAILEDFailed to create a new QR session on the server.
POLLING_FAILEDThe periodic check for a successful scan failed, possibly due to a server-side issue.
POLLING_ERRORAn unexpected client-side error occurred while checking for a scan status.
QR_INIT_FAILEDThe QR login process could not be started due to a critical client-side error.

Code Examples

const auth = await HawcxInitializer.init('YOUR_API_KEY');
// One intelligent method handles everything
auth.authenticate('[email protected]').then(response => {
  if (response.status === "SUCCESS") {
    // Smart Connect instantly authenticated known user on trusted device
    const token = response.data;
    // ...

  } else if (response.status === "OTP_NEEDED") {
    // Smart Connect requires verification for new user/device
    const deviceToken = response.data;
    // ...

  } else {
    throw Error(`Authentication failed: ${response.message}`)
  }
});
auth.verify({
  otp: "YOUR_OTP",
  deviceToken: deviceToken,
  userid: "[email protected]"
}).then(response => {
  if (response.status === "SUCCESS") {
    // Smart Connect authentication complete
    const accessToken = response.data;
    // ...

  } else {
    throw Error(`Verification failed: ${response.message}`);
  }
});
auth.initiateQrLogin({
  onPinReady: ({ web_pin }) => {
    // Use web_pin to generate a QR code for the user to scan
    console.log("QR Code PIN:", web_pin);
    // e.g., new QRCode(document.getElementById("qrcode"), web_pin);
  },
  onSuccess: (authResponse) => {
    // Smart Connect authenticated user via QR
    const accessToken = authResponse.data;
    console.log("Successfully authenticated via Smart Connect QR!");
    // Redirect or update UI
  },
  onError: (error) => {
    // Handle the error, e.g., show a "timed out" message
    console.error("QR Login Failed:", error.message);
  }
});
The future of authentication is here – and it’s Smart Connect. We’re continuously enhancing this revolutionary technology to deliver even more intelligent authentication experiences. Join our community on Slack for support and to share your feedback!
I