We are using Appcelerator Cloud Service (ACS) as a back-end for one of our mobile apps.  During the Go Live, one of our tasks was to move all data in the Development Database on ACS to Production.

Problem

We had to do a lot of calls from our local Node Server to the Appcelerator Cloud to get the data exported from Dev, cleaned up and uploaded to Production.  All worked fine for a while but then suddenly I started getting  a “User Not Authenticated” error.

When debugging I still found that the user is actually logged in but fails when either doing a delete, create or update to Appcelerator Cloud.  After a lot of troubleshooting I figured out that the Session Id from the Login Service was not being maintained across the different ACS calls.

Resolution

First thing is to create a global variable to store your sessionId:

var sessionId = "";

Then I create a normal login function to ACS and assign the sessionId to my variable:
The important part here is: sessionId = data.meta.session_id;

function _loginUser(req, res, options) {
    ACS.Users.login({
        login: username,
        password: password
    }, function (data) {
        if (data.success) {
//This is the important bit that needed to be added
            sessionId = data.meta.session_id;
            _StartDataImport(req, res, options);         
        } else {
            var errorMessage = ["Incorrect username and password"];
            _ReturnResult(res, 400, errorMessage);
        }
    }, req, res);
}

When performing a service call to the Appcelerator Cloud you then pass this stored variable:
The important part here is: session_id: sessionId,

function _DeleteRows(req, res) {
    ACS.Objects.remove({
        session_id: sessionId,
        classname: tableName,
        ids: itemsToDelete.join(",")
    }, function (deletedRows) {
        if (deletedRows.success) {
_ReturnResult(res, 200, ("All rows deleted!");                           
        } else {      
            _ReturnResult(res, 200, deletedRows);
        }
    }, req, res);
}

When you run your Node.ACS application now you will find that the authentication problem is no more.  I did notice in my Google ventures that other login problems also occur, but this was the one that fixed everything for me.