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

Get user in cloud function #269

Closed
flessard opened this issue Feb 5, 2016 · 9 comments
Closed

Get user in cloud function #269

flessard opened this issue Feb 5, 2016 · 9 comments
Labels
type:question Support or code-level question

Comments

@flessard
Copy link
Contributor

flessard commented Feb 5, 2016

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 ?

@drew-gross
Copy link
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?

@flessard
Copy link
Contributor Author

flessard commented Feb 5, 2016

Yes i have user logged.

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

@gfosco
Copy link
Contributor

gfosco commented Feb 6, 2016

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.

@flessard
Copy link
Contributor Author

flessard commented Feb 6, 2016

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"
}

@flessard
Copy link
Contributor Author

flessard commented Feb 7, 2016

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

@flessard
Copy link
Contributor Author

flessard commented Feb 9, 2016

Any follow up for this bug ?

@thibauddavid
Copy link

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

@flessard
Copy link
Contributor Author

@gfosco. Bug still present in 2.0.8...

@flessard
Copy link
Contributor Author

fix whit #373

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type:question Support or code-level question
Projects
None yet
Development

No branches or pull requests

5 participants