Skip to content

Commit

Permalink
fix(Auth): Fix google login timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
crazy-grizzly committed Mar 13, 2020
1 parent 39080a9 commit 53e7a57
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
8 changes: 4 additions & 4 deletions api/src/controllers/AuthController.js
Original file line number Diff line number Diff line change
Expand Up @@ -262,14 +262,14 @@ const jwtOrganisation = (req, res) => {
}
};

const googleSuccess = (req, res) => {
const googleSuccess = (user, response) => {
// we have successfully signed into google
// create a JWT and set it in the query params (only way to return it with a redirect)
createUserJWT(req.user, 'google')
.then(token => res.redirect(`/api${AUTH_JWT_SUCCESS}?access_token=${token}`))
createUserJWT(user, 'google')
.then(token => response.redirect(`/api${AUTH_JWT_SUCCESS}?access_token=${token}`))
.catch(
(err) => {
res
response
.status(status.INTERNAL_SERVER_ERROR)
.send(err);
}
Expand Down
6 changes: 4 additions & 2 deletions api/src/routes/HttpRoutes.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,13 +151,15 @@ if (process.env.GOOGLE_ENABLED) {
'google',
DEFAULT_PASSPORT_OPTIONS,
(error, user, info) => {
const defaultErrorMessage = 'Something bad happened';

if (!user) {
response.redirect(`/api${routes.OAUTH2_FAILED}?error=${info.message}`);
response.redirect(`/api${routes.OAUTH2_FAILED}?error=${get(info, 'message', defaultErrorMessage)}`);

return;
}

AuthController.googleSuccess(request, response);
AuthController.googleSuccess(user, response);
},
)(request, response, next);
},
Expand Down

0 comments on commit 53e7a57

Please sign in to comment.