Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Getting Invalid session token(code: 209) while session token exist in _Session table #3763

Closed
zack1991 opened this issue Apr 28, 2017 · 3 comments

Comments

@zack1991
Copy link

zack1991 commented Apr 28, 2017

Hi,

I am getting the Invalid session token(code: 209) while my session token exist in the _Session table. I am just sharing the cloud code where i am getting this error.

main.js :-

Parse.Cloud.define("ping", function (req, res) {
    try {
        if (req.user !== undefined) {
            var userId = req.params.hasOwnProperty(GameConstants.USER_ID) && req.params.user_id !== "" ? req.params.user_id : req.user.get("username");
            LoginHelper.updateUserSessionEndDateTime(userId, function (error, status) {
                if (error) {
                    res.success({result: 0, custom_error_code: error.code, custom_error_message: error.message}); 
//{"result":0,"custom_error_code":209,"custom_error_message":"invalid session token"} - error comes in this part

                    //custom log
                    logger.info({result: 0, custom_error_code: error.code, custom_error_message: error.message});
                } else if (status === 0) {
                    res.success({result: 0, custom_error_code: CustomErrorCode.INVALID_USER_ERROR, custom_error_message: "Inavalid user"});

                    //custom log
                    logger.info({result: 0, custom_error_code: error.code, custom_error_message: error.message});
                } else {
                    CommonHelper.recordBuyerSessionData(userId);
                    res.success({result: 1});
                }
            });
        } else {
            res.success({result: 0, custom_error_code: CustomErrorCode.INVALID_USER_ERROR, custom_error_message: "Inavalid user"});

            //custom log
            logger.info({result: 0, custom_error_code: CustomErrorCode.INVALID_USER_ERROR, custom_error_message: "Inavalid user"});
        }
    } catch (e) {
        res.success({result: 0, custom_error_code: e.code, custom_error_message: e.message, stacktrace: e.stack});

        //custom log
        logger.info({result: 0, custom_error_code: e.code, custom_error_message: e.message, stacktrace: e.stack});
    }
}

LoginHelper.js :-

updateUserSessionEndDateTime: function (userId, callback) {
        var query = new Parse.Query(Parse.Object.extend("GameUser"));
        query.select("session_end_date_time");
        query.equalTo(GameConstants.OBJECT_ID, userId);
        query.first({
            success: function (gameUser) {
                if (typeof gameUser !== "undefined") {
                    //console.log("updateUserSessionEndDateTime data===========> " + JSON.stringify(gameUser));
                    gameUser.set(GameConstants.SESSION_END_DATE_TIME, new Date());
                    gameUser.save(null, {
                        success: function (gameUser) {
                            //console.log("updateUserSessionEndDateTime.save.success===========> " + JSON.stringify(gameUser));
                            callback(null, 1);
                        },
                        error: function (error) {
                            //console.log("updateUserSessionEndDateTime.save.error===========> " + error.message);
                            callback(error);
                        }
                    });
                } else {
                    //console.log("updateUserSessionEndDateTime.sessionData-------> undefined ");
                    callback(null, 0);
                }
            },
            error: function (error) {
                //console.log("updateUserSessionEndDateTime.error===========> " + error.message);
                callback(error);
            }
        });
    }

Error Logs -

{"result":0,"custom_error_code":209,"custom_error_message":"invalid session token"}{"result":0,"custom_error_code":209,"custom_error_message":"invalid session token"}{"result":0,"custom_error_code":209,"custom_error_message":"invalid session token"}{"result":0,"custom_error_code":209,"custom_error_message":"invalid session token"}{"result":0,"custom_error_code":209,"custom_error_message":"invalid session token"}{"result":0,"custom_error_code":209,"custom_error_message":"invalid session token"}{"result":0,"custom_error_code":209,"custom_error_message":"invalid session token"}

After user login successfully then calling ping cloud function. I don't want to remove ACL to solve this issue. I kindly request you to please help me why i am getting this issue, its urngent for me to solve this issue.

Thanks

@zack1991 zack1991 changed the title Invalid session token while session token exist in _Session table Getting Invalid session token(code: 209) while session token exist in _Session table Apr 28, 2017
@flovilmart
Copy link
Contributor

In your login helper, you should either pass the masterKey or the user's session token (from the original request) in order for the save to execute correctly. What happens here is that your save call is not authenticated, and the security prevents updating the object.

@zack1991
Copy link
Author

zack1991 commented May 8, 2017

Hi flovilmart, thanks for reply. I just updated my parse server from 2.3.1 to 2.3.8, now i am not getting this issue.

@flovilmart
Copy link
Contributor

So if everything's good can you close the issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants