From 0db858b04cf40030dc3303a1d1e1653fbd106e71 Mon Sep 17 00:00:00 2001 From: Benjamin Wilson Friedman Date: Tue, 24 Oct 2017 12:47:26 -0700 Subject: [PATCH] Enables login over POST in addition to GET (#4268) * Enables login over POST in addition to GET * Removes explcit method:POST as rp.post does this naturally --- spec/ParseUser.spec.js | 24 ++++++++++++++++++++++++ src/Routers/UsersRouter.js | 1 + 2 files changed, 25 insertions(+) diff --git a/spec/ParseUser.spec.js b/spec/ParseUser.spec.js index 73ba94e1..c9f0e972 100644 --- a/spec/ParseUser.spec.js +++ b/spec/ParseUser.spec.js @@ -126,6 +126,30 @@ describe('Parse.User testing', () => { }); }); + it('user login using POST with REST API', (done) => { + Parse.User.signUp('some_user', 'some_password', null, { + success: () => { + return rp.post({ + url: 'http://localhost:8378/1/login', + headers: { + 'X-Parse-Application-Id': Parse.applicationId, + 'X-Parse-REST-API-Key': 'rest', + }, + json: { + username: 'some_user', + password: 'some_password', + } + }).then((res) => { + expect(res.username).toBe('some_user'); + done(); + }).catch((err) => { + fail(`no request should fail: ${JSON.stringify(err)}`); + done(); + }); + }, + }); + }); + it("user login", (done) => { Parse.User.signUp("asdf", "zxcv", null, { success: function() { diff --git a/src/Routers/UsersRouter.js b/src/Routers/UsersRouter.js index 407d5619..ec1116b0 100644 --- a/src/Routers/UsersRouter.js +++ b/src/Routers/UsersRouter.js @@ -256,6 +256,7 @@ export class UsersRouter extends ClassesRouter { this.route('PUT', '/users/:objectId', req => { return this.handleUpdate(req); }); this.route('DELETE', '/users/:objectId', req => { return this.handleDelete(req); }); this.route('GET', '/login', req => { return this.handleLogIn(req); }); + this.route('POST', '/login', req => { return this.handleLogIn(req); }); this.route('POST', '/logout', req => { return this.handleLogOut(req); }); this.route('POST', '/requestPasswordReset', req => { return this.handleResetRequest(req); }); this.route('POST', '/verificationEmailRequest', req => { return this.handleVerificationEmailRequest(req); });