NodeJs Sample (how to handle return codes)Solved

I have been playing around with nodejs sample and notice that while checking for license in ta.CheckAndSavePKey(userEnteredPkey, TA_USER) the response I get is not an array but an object and therefore it always fail even for a valid key

if (retObj === null) (retObj comes as 0 in case of active okay) return null;

if (retObj[0] === TA_OK) //THIS IS NOT AN ARRAY. { // the customer activated successfully, begin your app BeginYourApp(); }

We can't reproduce this. Follow the example. In it you'll see how to properly handle returns from CheckAndSavePKey (note: it doesn't check an array value -- you're likely getting confused by the flow of promises).

Open main.js, look inside PromptForProductKey() for an example of how to properly call the function.

https://wyday.com/limelm/help/using-turboactivate-with-electron-nodejs/#prompt-pkey

And don't use 3rd party examples.

I am not following any third party example.

router.post('/activation/activate', function (req, res) { let license = req.param('license'); if(license){ let success = false;

ta.CheckAndSavePKey(license, TA_USER) .then((retObj) => {

// the product key was valid and saved successfully if (retObj === TA_OK) return ta.Activate(); else // TA_FAIL { console.log("Something failed! " + retObj, 1); return null; } }) .then((retObj) => { // result from Activate()

console.log("retObj "+retObj); console.log("retObj[0] "+retObj[0]); // if null, fall through if (retObj === null) return null;

if (retObj[0] === TA_OK) { // the customer activated successfully, begin your app success = true; console.log("Activation Successful.", retObj);

} else { console.log("Activation failed.", retObj); } }) .catch((retObj) => { // an error somewhere in the processing console.log("Something failed! " + retObj, 1); });

if(success){ loadmyapp(); }else{ return res.status(401).send(' Activation failed! '); } }});

Console Outout:

retObj 0retObj[0] undefinedActivation failed. 0

If I refresh my page I can login as I am checking (ta.IsGenuineEx) if its not activated got to above function else load the app. So on refresh ta.IsGenuineEx comes true.

Are you using it in a browser? Use NodeJS. Use a debugger and add breakpoints to see where things are going wrong.

No, I am using this at the server. This is a post request I created on server: router.post('/activation/activate')

I did put a debug marker and see the value and it shows retObj as 0 (TA_OK) and if revoke the key from dashboard it shows at 6 ( I guess which is global.TA_E_REVOKED = 0x06)

retObj [0] is always undefined so means there is no key defined as 0

I am using Node v10.18.1

Ok, our example and documentation had a typo. Remove the "[0]" from the return promise for Activate(). It returns a scalar not an array. The documentation fix will be pushed live later today. And the example fix will be in the next version (no hard date).

TA 4.3.2 has the fixed example app.