Commit 6cecf9fb authored by Matija Obreza's avatar Matija Obreza

Fix: Handle invalid CLIENT_ID and SECRET

- Prevents infinite loop
parent 3d1dc1a2
...@@ -23,7 +23,7 @@ const i18nServer = i18n ...@@ -23,7 +23,7 @@ const i18nServer = i18n
order: ['path'], order: ['path'],
lookupFromPathIndex: 0, lookupFromPathIndex: 0,
}, },
...optionsBase ...optionsBase,
}); });
export default i18nServer; export default i18nServer;
...@@ -22,10 +22,14 @@ ...@@ -22,10 +22,14 @@
"build": "webpack --config config/webpack-development.config.js", "build": "webpack --config config/webpack-development.config.js",
"build:production": "cross-env NODE_ENV=production SSR=true webpack --config config/webpack-production.config.js", "build:production": "cross-env NODE_ENV=production SSR=true webpack --config config/webpack-production.config.js",
"build:server": "cross-env NODE_ENV=production SSR=true webpack --config config/server.config.js", "build:server": "cross-env NODE_ENV=production SSR=true webpack --config config/server.config.js",
"build:serverdebug": "cross-env SSR=true webpack --config config/server.config.js",
"serve": "webpack-dev-server --config config/webpack-development.config.js", "serve": "webpack-dev-server --config config/webpack-development.config.js",
"serve:production": "cross-env NODE_ENV=production webpack-dev-server --config config/webpack-production.config.js", "serve:production": "cross-env NODE_ENV=production webpack-dev-server --config config/webpack-production.config.js",
"build:ssr": "rimraf target && npm run build:production && npm run build:server", "build:ssr": "rimraf target && npm run build:production && npm run build:server",
"serve:ssr": "npm run build:ssr && cd target/app/server && cross-env SSR=true node server.js", "serve:ssr": "npm run build:ssr && cd target/app/server && cross-env SSR=true node server.js",
"build:ssrdebug": "rimraf target && npm run build && npm run build:serverdebug",
"debug:ssr": "npm run build:ssrdebug && cd target/app/server && cross-env SSR=true node server.js",
"ssr": "cd target/app/server && cross-env SSR=true node server.js",
"i18nscan": "i18next-scanner --config i18next-scanner.config.js 'src/**/*.tsx'" "i18nscan": "i18next-scanner --config i18next-scanner.config.js 'src/**/*.tsx'"
}, },
"dependencies": { "dependencies": {
......
import { checkTokenRequest, loginAppRequest, loginUser } from 'actions/login'; import { checkTokenRequest, loginAppRequest, loginUser } from 'actions/login';
import ApiError from 'model/ApiError';
function checkAuthTokenRequest(req, dispatch) { function checkAuthTokenRequest(req, dispatch) {
const token = req.cookies.access_token; const token = req.cookies.access_token;
...@@ -9,12 +10,12 @@ function checkAuthTokenRequest(req, dispatch) { ...@@ -9,12 +10,12 @@ function checkAuthTokenRequest(req, dispatch) {
console.log(`User token ${token} is valid, response`, checkedToken); console.log(`User token ${token} is valid, response`, checkedToken);
return dispatch(loginUser(checkedToken)); return dispatch(loginUser(checkedToken));
}) })
.catch(() => { .catch((err) => {
console.log('Server: check failed dispatching loginAppRequest'); console.log('Cookie check failed, dispatching loginAppRequest', ApiError.axiosError(err));
return dispatch(loginAppRequest()); return dispatch(loginAppRequest());
}); });
} else { } else {
console.log('Server: No token in cookie, dispatching loginAppRequest'); console.log('No token in cookie, dispatching loginAppRequest');
return dispatch(loginAppRequest()); return dispatch(loginAppRequest());
} }
} }
...@@ -31,9 +32,10 @@ export default function checkAuthToken(req, res, dispatch) { ...@@ -31,9 +32,10 @@ export default function checkAuthToken(req, res, dispatch) {
res.clearCookie('authorities'); res.clearCookie('authorities');
} }
return data; return data;
}).catch((x) => { }).catch((err) => {
console.log('Failed checkAuthToken, clearing cookies', x); console.log('Failed checkAuthToken, clearing cookies', ApiError.axiosError(err));
res.clearCookie('access_token'); res.clearCookie('access_token');
res.clearCookie('authorities'); res.clearCookie('authorities');
return Promise.reject({ message: 'Could not authenticate against the API.' });
}); });
} }
...@@ -14,7 +14,7 @@ export default function fetchComponentData(dispatch, branch, search) { ...@@ -14,7 +14,7 @@ export default function fetchComponentData(dispatch, branch, search) {
}).forEach((promise) => { }).forEach((promise) => {
console.log(`Component ${component} needs`, promise); console.log(`Component ${component} needs`, promise);
// a nice array of Promises // a nice array of Promises
promisesWithProps.push(promise) promisesWithProps.push(promise);
}); });
}); });
......
...@@ -139,6 +139,9 @@ const prerenderer = (html) => (req, res) => { ...@@ -139,6 +139,9 @@ const prerenderer = (html) => (req, res) => {
console.error('Error:', err); console.error('Error:', err);
res.status(500).end(err.message); res.status(500).end(err.message);
}); });
}).catch((err) => {
console.error('Error:', err);
res.status(500).end(err.message);
}); });
}; };
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment