Skip to content

Commit

Permalink
Merge 6e604c3 into b559f30
Browse files Browse the repository at this point in the history
  • Loading branch information
gadishimwe committed Feb 14, 2020
2 parents b559f30 + 6e604c3 commit 7e5a067
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
2 changes: 2 additions & 0 deletions .env-sample
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,5 @@ GOOGLE_CLIENT_SECRET={your client secret}
#Facebook auth keys
FACEBOOK_APP_ID={your client id}
FACEBOOK_APP_SECRET={your client secret}

FRONTEND_URL={for example, our heroku frontend url}
6 changes: 4 additions & 2 deletions src/controllers/auth.controller.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import dotenv from 'dotenv';
import ResponseService from '../services/response.service';
import UserService from '../services/user.service';
import BcryptService from '../services/bcrypt.service';
Expand All @@ -6,6 +7,8 @@ import SendEmailService from '../services/send-email.service';
import PreferenceService from '../services/preference.service';
import emailNotification from '../helpers/mails/email-notification.mail';

dotenv.config();

/**
*
*
Expand Down Expand Up @@ -187,8 +190,7 @@ class AuthController {
static async googleFacebookAuthHandler(req, res) {
const token = JwtService.generateToken({ id: req.user.id });
await UserService.updateUser({ id: req.user.id }, { token });
ResponseService.setSuccess(200, `Successfully logged in with your ${req.user.provider} account`, { token });
return ResponseService.send(res);
return res.redirect(`${process.env.FRONTEND_URL}/facebook/redirect?token=${token}`);
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/tests/auth/google-facebook-auth.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ describe('Test Google and Facebook authentication:', () => {
sinon.restore();
});
it('Should return status code 200 on successiful login with google or facebook', async () => {
const res = await AuthController.googleFacebookAuthHandler({ user: googleFacebookUser }, resp);
expect(res.statusCode).to.equal(200);
await AuthController.googleFacebookAuthHandler({ user: googleFacebookUser }, resp);
expect(resp.finished).to.equal(true);
});
it('should return data from google user profile', async () => {
const callBack = sinon.spy();
Expand Down

0 comments on commit 7e5a067

Please sign in to comment.