Skip to content

request.user is "undefined" in the "beforeSave" function in the Cloud code #2930

@grassland-curing-cfa

Description

@grassland-curing-cfa

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.

  1. 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions