Closed
Description
Successfully reproduced this in both my env and parse-server-example, so I doubt this is an issue with our own setup. The following setup/reproduction/log are on a newly cloned parse-server-example.
A sessionToken is included when calling cloud_function_2
from cloud_function_1
, but req.user
is still undefined in cloud_function_2
.
I've previously submitted similar (and I think related) issue #1404, and was advised that I should have revocable session enabled. But this also happens when cloud_function_1
is called by the iOS client that has it enabled [PFUser enableRevocableSessionInBackground]
.
Please note when cloud_function_2
is directly called by the client, req.user
exists with correct token.
Environment Setup
{
"express": "~4.11.x",
"kerberos": "~0.0.x",
"parse": "~1.8.0",
"parse-server": "~2.2.2"
}
Steps to reproduce
node test_session
with the following:
// test_session file
#!/usr/bin/env node
var APP_ID = process.env.APP_ID || "myAppId";
var JAVASCRIPT_KEY = process.env.JAVASCRIPT_KEY || "myJavascriptKey";
var Parse = require('parse/node');
Parse.initialize(APP_ID, JAVASCRIPT_KEY);
Parse.serverURL = process.env.SERVER_URL || "http://localhost:1337/parse";
console.log("test_session started");
var now = new Date();
var username = now.valueOf().toString();
var user = new Parse.User();
user.set("username", username);
user.set("password", "my pass");
user.set("email", username+"@example.com");
console.log("signing up user " + now.valueOf());
user.signUp().then(function(user) {
console.log("calling cloud_function_1 with session token: " + user.getSessionToken());
Parse.Cloud.run("cloud_function_1", null, {
sessionToken: user.getSessionToken()
})
}, function(error){
console.log(error);
})
// main.js file
Parse.Cloud.define("cloud_function_1", function(req, res){
console.log("\ncloud_function_1 was called by user: " + JSON.stringify(req.user));
console.log("\ncalling cloud_function_2 from cloud_function_1 using sessionToken: " + req.user.getSessionToken());
Parse.Cloud.run("cloud_function_2", null, {
sessionToken: req.user.getSessionToken
}).then(function(){
res.success()
}, function(error){
res.error(error);
});
})
Parse.Cloud.define("cloud_function_2", function(req, res){
console.log("\ncloud_function_2 was called by user: " + JSON.stringify(req.user));
var response = req.user ? req.user.getSessionToken() : "req.user in cloud_function_2 is undefined";
res.success(response);
})
Logs/Trace
test_session started
signing up user 1460659687620
calling cloud_function_1 with session token: r:aa6ca22622c660f139fc2b0e9a249b6d
DATABASE_URI not specified, falling back to localhost.
verbose: Support key pairs Map {}
parse-server-example running on port 1337.
verbose: POST /parse/users { 'user-agent': 'node-XMLHttpRequest, Parse/js1.8.3 (NodeJS 4.3.1)',
accept: '*/*',
'content-type': 'text/plain',
host: 'localhost:1337',
'content-length': '231',
connection: 'close' } {
"username": "1460659687620",
"password": "my pass",
"email": "[email protected]"
}
verbose: {
"status": 201,
"response": {
"objectId": "BWo3njwpYQ",
"createdAt": "2016-04-14T18:48:07.687Z",
"sessionToken": "r:aa6ca22622c660f139fc2b0e9a249b6d"
},
"location": "http://localhost:1337/parse/users/BWo3njwpYQ"
}
verbose: POST /parse/functions/cloud_function_1 { 'user-agent': 'node-XMLHttpRequest, Parse/js1.8.3 (NodeJS 4.3.1)',
accept: '*/*',
'content-type': 'text/plain',
host: 'localhost:1337',
'content-length': '200',
connection: 'close' } {}
cloud_function_1 was called by user: {"ACL":{"BWo3njwpYQ":{"read":true,"write":true},"*":{"read":true}},"username":"1460659687620","email":"[email protected]","updatedAt":"2016-04-14T18:48:07.687Z","createdAt":"2016-04-14T18:48:07.687Z","sessionToken":"r:aa6ca22622c660f139fc2b0e9a249b6d","objectId":"BWo3njwpYQ"}
calling cloud_function_2 from cloud_function_1 using sessionToken: r:aa6ca22622c660f139fc2b0e9a249b6d
verbose: POST /parse/functions/cloud_function_2 { 'user-agent': 'node-XMLHttpRequest, Parse/js1.8.3 (NodeJS 4.3.1)',
accept: '*/*',
'content-type': 'text/plain',
host: 'localhost:1337',
'content-length': '138',
connection: 'close' } {}
cloud_function_2 was called by user: undefined
verbose: {
"response": {
"result": "req.user in cloud_function_2 is undefined"
}
}
verbose: {
"response": {}
}
Metadata
Metadata
Assignees
Labels
No labels