### Initializing Hawcx SDK via CDN Source: https://github.com/hawcx/hawcx_web_demo/blob/main/README.md This snippet shows how to include the Hawcx SDK in an HTML file using a CDN and initialize it with your API key. The SDK is imported as a module. ```html ``` -------------------------------- ### Registering User with Hawcx Source: https://github.com/hawcx/hawcx_web_demo/blob/main/README.md This code demonstrates the two-step process for user registration: initiating the sign-up with an email and then verifying the user by submitting the OTP received. ```javascript // Register a new user auth.signUp('user@example.com').then(response => { if (response.success) { console.log('Verification code sent!', response.data.sessionId); // Prompt user to enter OTP } else { console.error('Registration failed:', response.message); } }); // Verify OTP for registration auth.verifyOTP('123456').then(response => { if (response.success) { console.log('Registration completed successfully!'); // User is now registered } else { console.error('Verification failed:', response.message); } }); ``` -------------------------------- ### Adding and Verifying New Device with Hawcx Source: https://github.com/hawcx/hawcx_web_demo/blob/main/README.md This code illustrates the process of registering a new device for an existing user. It covers initiating the device addition flow and then verifying the device using an OTP. ```javascript // When a user tries to login from a new device auth.addDevice() .then(response => { if (response.success) { console.log("Verification code sent for new device!"); // Prompt user to enter the verification code } else { console.error("Device verification initiation failed:", response.message); } }); // Verify the OTP for the new device auth.verifyOTP('123456', true) .then(response => { if (response.success) { console.log("New device registered successfully!"); // Now the user can login from this device } else { console.error("Device verification failed:", response.message); } }); ``` -------------------------------- ### Authenticating User with Hawcx Source: https://github.com/hawcx/hawcx_web_demo/blob/main/README.md This snippet shows how to sign in an existing user. It also includes handling the specific case where the device is not registered, prompting the user to add the device. ```javascript // Authenticate a user auth.signIn('user@example.com') .then(response => { if (response.success) { console.log("Signed in successfully!"); // Handle authentication tokens const { access_token, refresh_token } = response.data; // Store tokens as needed } else if (response.errorCode === 'DEVICE_NOT_REGISTERED') { // This device is not registered, send verification return auth.addDevice(); } else { console.error("Authentication failed:", response.message); } }); ``` -------------------------------- ### Hawcx API Response Structure Source: https://github.com/hawcx/hawcx_web_demo/blob/main/README.md This snippet describes the standard format of the response object returned by most Hawcx authentication methods, indicating the outcome, message, error code, and any relevant data. ```javascript { success: true/false, // Whether the operation succeeded message: "Message text", // User-friendly message errorCode: "ERROR_CODE", // Error code (null if success) data: { ... } // Additional data (varies by method) } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.