Skip to content

Get user in cloud function #269

Closed
Closed

Description

@flessard

How i can get the user made the request in cloud function ?
i try request.user but is always null.

Is possible in parse-server to get this information ?

Activity

  1. drew-gross commented on Feb 5, 2016

    @drew-gross
    Contributor

    request.user in the correct way, if it is null that could indicate that there is no user logged in to your app. Could you check that you have a logged in user, and if you still have issues, respond with some detailed reproduction steps?

  2. flessard commented on Feb 5, 2016

    @flessard
    ContributorAuthor

    Yes i have user logged.

    I just call a cloud function from my web app using javascript SDK js1.6.14.

  3. gfosco commented on Feb 6, 2016

    @gfosco
    Contributor

    Can you capture the request being made to the server? One way is to run the server with an environment variable set, VERBOSE=1 In this case it sounds like the session token may not be present.

  4. flessard commented on Feb 6, 2016

    @flessard
    ContributorAuthor

    Voilà !

    POST / folo / functions / getUserRole {
        host: '127.0.0.1:5000',
        connection: 'keep-alive',
        'content-length': '324',
        origin: 'http://folo.local',
        'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/48.0.2564.103 Safari/537.36',
        'content-type': 'text/plain',
        accept: '*/*',
        referer: 'http://folo.local/dashboard/',
        'accept-encoding': 'gzip, deflate',
        'accept-language': 'en,en-US;q=0.8,en-GB;q=0.6,fr;q=0.4'
    } {
        "u": {
            "__type": "Pointer",
            "className": "_User",
            "objectId": "IDuau99xWH"
        }
    }
    

    and this my Request payload in Goole Chrome

    {
        "u": {
            "__type": "Pointer",
            "className": "_User",
            "objectId": "IDuau99xWH"
        },
        "_ApplicationId": "hidden",
        "_JavaScriptKey": "hidden",
        "_ClientVersion": "js1.6.14",
        "_InstallationId": "e74eaa34-bf91-8521-5d46-0582f1e9c742",
        "_SessionToken": "FLA7Pe97OV3i4iJr6vUL6jG2H"
    }
    
  5. flessard commented on Feb 7, 2016

    @flessard
    ContributorAuthor

    @gfosco I found the problem. In _User collection a field _session_token is present and if you fetch the user data form server, this field override the sessionToken saved in your browser.

    If you don't fetch the user, all request to server contain the right sessionToken and if you fetch the user data from the server, all next requests will contain the bad sessionToken come form the _session_token in user data fetched.

  6. flessard commented on Feb 9, 2016

    @flessard
    ContributorAuthor

    Any follow up for this bug ?

  7. thibauddavid commented on Feb 10, 2016

    @thibauddavid

    +1, parse-server is not really usable in most cases without request.user returning client's user

  8. flessard commented on Feb 11, 2016

    @flessard
    ContributorAuthor

    @gfosco. Bug still present in 2.0.8...

  9. flessard commented on Feb 16, 2016

    @flessard
    ContributorAuthor

    fix whit #373

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    type:questionSupport or code-level question

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions