diff --git a/.env-sample b/.env-sample index 64b089de..04082e46 100644 --- a/.env-sample +++ b/.env-sample @@ -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} diff --git a/src/controllers/auth.controller.js b/src/controllers/auth.controller.js index 0f7a8221..2bb6c8d2 100644 --- a/src/controllers/auth.controller.js +++ b/src/controllers/auth.controller.js @@ -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'; @@ -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(); + /** * * @@ -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}`); } } diff --git a/src/tests/auth/google-facebook-auth.test.js b/src/tests/auth/google-facebook-auth.test.js index 9431817e..d0d221bf 100644 --- a/src/tests/auth/google-facebook-auth.test.js +++ b/src/tests/auth/google-facebook-auth.test.js @@ -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();