-
-
Couldn't load subscription status.
- Fork 4.8k
Closed
Description
Issue Description
I'm trying to authorize a user through facebook. For this I use the cloud function facebook, which takes an object of the form:
{
"data": {
"email": <email>,
"authData": {
"id": <user_id>,
"access_token": <user_access_token>
}
}
}
My code:
cloud/main.js
const AuthModule = require('./modules/AuthModule');
Parse.Cloud.define('facebook', async function (req, res) {
const user = await AuthModule.facebook(req.params.data);
return user.toJSON();
});
cloud/modules/AuthModule
const randomstring = require('randomstring');
module.exports = AuthModule = {
facebook: function (data) {
return new Promise((resolve, reject) => {
const query = new Parse.Query(Parse.User);
query.equalTo('email', data.email);
query.first({ useMasterKey: true })
.then(async user => {
if (!user) {
user = new Parse.User();
user.set('password', randomstring.generate());
user.set('username', data.email);
user.set('email', data.email);
user = await user.signUp(null);
}
user._linkWith('facebook', { authData: data.authData })
.then(user => resolve(user))
.catch(error => reject(error));
})
.catch(error => reject(error));
});
},
}
Steps to reproduce
Run the command:
curl -X POST \
-H "X-Parse-Application-Id: APPLICATION_ID" \
-H "X-Parse-REST-API-Key: REST_API_KEY" \
-H "Content-Type: application/json" \
-d '{ "data": { "email": <email>, "authData": { "id": <user_id>, "access_token": <user_access_token> } } }' \
http://localhost:1337/parse/functions/facebook
Expected Results
The _linkWith method succeeds.
Actual Outcome
The _linkWith method fails.
This is because the _linkWith method calls the Parse.User#save method without the option object with the useMasterKey: true.
Link to code
Environment Setup
-
Server
- parse-server version (Be specific! Don't say 'latest'.) : 3.0.0
- Operating System: Ubuntu 16.04.5 LTS
- Localhost or remote server? (AWS, Heroku, Azure, Digital Ocean, etc): localhost
-
Database
- MongoDB version: 3.6.6
- Storage engine: MMAPv1
- Localhost or remote server? (AWS, mLab, ObjectRocket, Digital Ocean, etc): mLab
Logs/Trace
Metadata
Metadata
Assignees
Labels
No labels