diff --git a/src/components/Page/Page.js b/src/components/Page/Page.js
index f53f0aa4..e9367626 100644
--- a/src/components/Page/Page.js
+++ b/src/components/Page/Page.js
@@ -54,7 +54,6 @@ class PageComponent extends Component {
const {
className,
rootClassName,
- authInfoError,
children,
history,
intl,
@@ -77,9 +76,6 @@ class PageComponent extends Component {
// TODO: use FlashMessages for auth errors
/* eslint-disable no-console */
- if (authInfoError && console && console.error) {
- console.error(authInfoError);
- }
if (logoutError && console && console.error) {
console.error(logoutError);
}
@@ -184,11 +180,6 @@ class PageComponent extends Component {
{metaTags}
- {authInfoError ? (
-
-
-
- ) : null}
{logoutError ? (
@@ -206,7 +197,6 @@ PageComponent.defaultProps = {
className: null,
rootClassName: null,
children: null,
- authInfoError: null,
logoutError: null,
scrollingDisabled: false,
author: null,
@@ -226,7 +216,6 @@ PageComponent.propTypes = {
className: string,
rootClassName: string,
children: any,
- authInfoError: propTypes.error,
logoutError: propTypes.error,
scrollingDisabled: bool,
diff --git a/src/ducks/Auth.duck.js b/src/ducks/Auth.duck.js
index 5705062d..606268ab 100644
--- a/src/ducks/Auth.duck.js
+++ b/src/ducks/Auth.duck.js
@@ -2,13 +2,12 @@ import { clearCurrentUser, fetchCurrentUser } from './user.duck';
import { storableError } from '../util/errors';
import * as log from '../util/log';
-const authenticated = authInfo => authInfo.grantType === 'refresh_token';
+const authenticated = authInfo => authInfo && authInfo.grantType === 'refresh_token';
// ================ Action types ================ //
export const AUTH_INFO_REQUEST = 'app/Auth/AUTH_INFO_REQUEST';
export const AUTH_INFO_SUCCESS = 'app/Auth/AUTH_INFO_SUCCESS';
-export const AUTH_INFO_ERROR = 'app/Auth/AUTH_INFO_ERROR';
export const LOGIN_REQUEST = 'app/Auth/LOGIN_REQUEST';
export const LOGIN_SUCCESS = 'app/Auth/LOGIN_SUCCESS';
@@ -33,7 +32,6 @@ const initialState = {
// auth info
authInfoLoaded: false,
- authInfoError: null,
// login
loginError: null,
@@ -52,12 +50,9 @@ export default function reducer(state = initialState, action = {}) {
const { type, payload } = action;
switch (type) {
case AUTH_INFO_REQUEST:
- return { ...state, authInfoError: null };
+ return state;
case AUTH_INFO_SUCCESS:
return { ...state, authInfoLoaded: true, isAuthenticated: authenticated(payload) };
- case AUTH_INFO_ERROR:
- console.error(payload); // eslint-disable-line
- return { ...state, authInfoLoaded: true, authInfoError: payload };
case LOGIN_REQUEST:
return {
@@ -102,7 +97,6 @@ export const authenticationInProgress = state => {
export const authInfoRequest = () => ({ type: AUTH_INFO_REQUEST });
export const authInfoSuccess = info => ({ type: AUTH_INFO_SUCCESS, payload: info });
-export const authInfoError = error => ({ type: AUTH_INFO_ERROR, payload: error, error: true });
export const loginRequest = () => ({ type: LOGIN_REQUEST });
export const loginSuccess = () => ({ type: LOGIN_SUCCESS });
@@ -125,7 +119,15 @@ export const authInfo = () => (dispatch, getState, sdk) => {
return sdk
.authInfo()
.then(info => dispatch(authInfoSuccess(info)))
- .catch(e => dispatch(authInfoError(storableError(e))));
+ .catch(e => {
+ // Requesting auth info just reads the token from the token
+ // store (i.e. cookies), and should not fail in normal
+ // circumstances. If it fails, it's due to a programming
+ // error. In that case we mark the operation done and dispatch
+ // `null` success action that marks the user as unauthenticated.
+ log.error(e, 'auth-info-failed');
+ dispatch(authInfoSuccess(null));
+ });
};
export const login = (username, password) => (dispatch, getState, sdk) => {
diff --git a/src/ducks/Auth.test.js b/src/ducks/Auth.test.js
index 9865290a..d1a79c28 100644
--- a/src/ducks/Auth.test.js
+++ b/src/ducks/Auth.test.js
@@ -3,7 +3,6 @@ import { clearCurrentUser, currentUserShowRequest, currentUserShowSuccess } from
import reducer, {
authenticationInProgress,
authInfoSuccess,
- authInfoError,
login,
loginRequest,
loginSuccess,
@@ -51,7 +50,6 @@ describe('Auth duck', () => {
const state = reducer();
expect(state.isAuthenticated).toEqual(false);
expect(state.authInfoLoaded).toEqual(false);
- expect(state.authInfoError).toBeNull();
expect(state.loginError).toBeNull();
expect(state.logoutError).toBeNull();
expect(state.signupError).toBeNull();
@@ -165,7 +163,6 @@ describe('Auth duck', () => {
const state = reducer(initialState, authInfoSuccess(authInfoLoggedOut));
expect(state.authInfoLoaded).toEqual(true);
expect(state.isAuthenticated).toEqual(false);
- expect(state.authInfoError).toBeNull();
});
it('should set initial state for anonymous users', () => {
@@ -175,7 +172,6 @@ describe('Auth duck', () => {
const state = reducer(initialState, authInfoSuccess(authInfoAnonymous));
expect(state.authInfoLoaded).toEqual(true);
expect(state.isAuthenticated).toEqual(false);
- expect(state.authInfoError).toBeNull();
});
it('should set initial state for unauthenticated users', () => {
@@ -185,7 +181,6 @@ describe('Auth duck', () => {
const state = reducer(initialState, authInfoSuccess(authInfoLoggedIn));
expect(state.authInfoLoaded).toEqual(true);
expect(state.isAuthenticated).toEqual(true);
- expect(state.authInfoError).toBeNull();
});
});
diff --git a/src/translations/en.json b/src/translations/en.json
index da6e5808..a62a09a0 100644
--- a/src/translations/en.json
+++ b/src/translations/en.json
@@ -276,7 +276,6 @@
"OrderPage.fetchOrderFailed": "Fetching order data failed.",
"OrderPage.loadingData": "Loading order data.",
"OrderPage.title": "Order details: {listingTitle}",
- "Page.authInfoFailed": "Could not get authentication information.",
"Page.logoutFailed": "Logout failed. Please try again.",
"Page.schemaDescription": "You can book a sauna from Saunatime or get some income by sharing your own sauna",
"Page.schemaTitle": "Book saunas everywhere | {siteTitle}",