parse-server: request.user is "undefined" in the "beforeSave" function in the Cloud code
In my ParseServer migrated into the Heroko + mLab stack,
I have a beforeSave function set for a custom “OBSERVATION” Class as below.
Parse.Cloud.beforeSave("OBSERVATION", function(request, response) {
... ...
var currUser = request.user;
console.log(request);
console.log("*** User objectId: " + currUser.id + "; " + currUser.getSessionToken());
... ...
});
I want to get the user name triggering the Save event. According to the Parse JavaScript SDK Reference, a “BeforeSaveRequest” takes a “user” as a member, which represents the User triggering the “Save” event.
However, this is always “undefined” for me. Is there anything I missed or did wrong?
Steps to reproduce
Please include a detailed list of steps that reproduce the issue. Include curl commands when applicable.
- In the BeforeSave function, add console.log(request);
Expected Results
{ triggerName: 'beforeSave',
**user: {ParseObject {
sessionToken: 'xxxxxxxxxxxxxxx',
id: 'hDijlsmDP'
}},**
object:
ParseObject {
_objCount: 1538,
className: 'OBSERVATION',
id: 'xUskfmanDY' },
master: true,
log: FileLoggerAdapter {},
original:
ParseObject {
_objCount: 1541,
className: 'OBSERVATION',
id: 'xUskfmanDY' }
}
Actual Outcome
{ triggerName: 'beforeSave',
object:
ParseObject {
_objCount: 1538,
className: 'OBSERVATION',
id: 'xUskfmanDY' },
master: true,
log: FileLoggerAdapter {},
original:
ParseObject {
_objCount: 1541,
className: 'OBSERVATION',
id: 'xUskfmanDY' }
}
Environment Setup
- Server
- parse-server version (Be specific! Don’t say ‘latest’.) : 2.2.15
- Operating System: Heroku Linux
- Hardware: Heroku Dyno
- Localhost or remote server? (AWS, Heroku, Azure, Digital Ocean, etc): Heroku
- Database
- MongoDB version: 3.0
- Storage engine: Unknown
- Hardware: Unknown
- Localhost or remote server? (AWS, mLab, ObjectRocket, Digital Ocean, etc): mLab
Logs/Trace
You can turn on additional logging by configuring VERBOSE=1 in your environment.
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Comments: 23 (11 by maintainers)
I am also seeing request.user as undefined on all beforeSave functions, even though request.user is correctly set on the Parse Cloud functions that trigger the beforeSave. I am using parse-server v2.2.4 and running it locally. Also seen on v2.2.22.
As I’ve been saying from the start, there is no user authenticated here (No Session-Token sent) and you are using the Master-Key.
I see that master is set to true here, how did you save the object that this beforeSave should be called on? Is a user authenticated?