Skip to content

Commit

Permalink
Merge pull request #978 from ParsePlatform/flovilmart.cleanupNullAuth…
Browse files Browse the repository at this point in the history
…DatakeysOnLogin

Fixes #935, cleans up authData null keys on login for android crash
  • Loading branch information
flovilmart committed Mar 11, 2016
2 parents d42d359 + 1ed868b commit cd7a4b8
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 1 deletion.
37 changes: 37 additions & 0 deletions spec/ParseUser.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

var request = require('request');
var passwordCrypto = require('../src/password');
var Config = require('../src/Config');

function verifyACL(user) {
const ACL = user.getACL();
Expand Down Expand Up @@ -1780,5 +1781,41 @@ describe('Parse.User testing', () => {
}
});
});

// Sometimes the authData still has null on that keys
// https://github.com/ParsePlatform/parse-server/issues/935
it('should cleanup null authData keys', (done) => {
let database = new Config(Parse.applicationId).database;
database.create('_User', {
username: 'user',
password: '$2a$10$8/wZJyEuiEaobBBqzTG.jeY.XSFJd0rzaN//ososvEI4yLqI.4aie',
_auth_data_facebook: null
}, {}).then(() => {
return new Promise((resolve, reject) => {
request.get({
url: 'http://localhost:8378/1/login?username=user&password=test',
headers: {
'X-Parse-Application-Id': 'test',
'X-Parse-Master-Key': 'test',
},
json: true
}, (err, res, body) => {
if (err) {
reject(err);
} else {
resolve(body);
}
})
})
}).then((user) => {
let authData = user.authData;
expect(user.username).toEqual('user');
expect(authData).toBeUndefined();
done();
}).catch((err) => {
fail('this should not fail');
done();
})
});
});

15 changes: 14 additions & 1 deletion src/Routers/UsersRouter.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,20 @@ export class UsersRouter extends ClassesRouter {
let token = 'r:' + cryptoUtils.newToken();
user.sessionToken = token;
delete user.password;


// Sometimes the authData still has null on that keys
// https://github.com/ParsePlatform/parse-server/issues/935
if (user.authData) {
Object.keys(user.authData).forEach((provider) => {
if (user.authData[provider] === null) {
delete user.authData[provider];
}
});
if (Object.keys(user.authData).length == 0) {
delete user.authData;
}
}

req.config.filesController.expandFilesInObject(req.config, user);

let expiresAt = new Date();
Expand Down

0 comments on commit cd7a4b8

Please sign in to comment.