Ejemplo n.º 1
0
  const requireLogin = async function(nextState, replace, cb) {
    function checkAuth() {
      const { auth: { user, token, tokenExpires }} = store.getState();
      //TODO: Handle token expiriation
      if (!user) {
        console.log('return');
        store.dispatch(removeToken());
        replace('/');
      }
      console.log('render');
      cb();
    }

    if (!isAuthRestored(store.getState())) {
      await loadFromStorage(store);
      store.dispatch(authenticate(store.getState().auth.token));
    }

    if (!isAuthLoaded(store.getState())) {
      store.dispatch(loadAuth()).then(checkAuth).catch(err => {
        replace('/')
        cb();
      });
    } else {
      checkAuth();
    }
  };
Ejemplo n.º 2
0
 const requireLogin = (nextState, replace, cb) => {
   if (!isAuthLoaded(store.getState())) {
     store.dispatch(loadAuth()).then(() => checkAuth(true, replace, cb));
   } else {
     checkAuth(true, replace, cb);
   }
 };
Ejemplo n.º 3
0
  const requireLogin = (nextState, replace, cb) => {
    function checkAuth() {
      const { auth: { user }} = store.getState();
      if (!user) {
        replace("/login?return=" + nextState.location.pathname);
      }
      cb();
    }

    if (!isAuthLoaded(store.getState())) {
      store.dispatch(loadAuth()).then(checkAuth);
    } else {
      checkAuth();
    }
  };
Ejemplo n.º 4
0
  const requireLogin = (nextState, replace, cb) => {
    function checkAuth() {
      const { auth: { user }} = store.getState();
      if (!user) {
        // oops, not logged in, so can't be here!
        replace('/');
      }
      cb();
    }

    if (!isAuthLoaded(store.getState())) {
      store.dispatch(loadAuth()).then(checkAuth);
    } else {
      checkAuth();
    }
  };
Ejemplo n.º 5
0
	const requireLogin = (nextState, replace, cb) => {
		function checkAuth() {
			const { auth: { user } } = store.getState();
			const { location: { pathname } } = nextState;

			if (!user) {
				replace(`/login${pathname ? '?returnUrl=' + pathname : ''}`);
			}
			cb();
		}

		if (!isLoaded(store.getState().auth)) {
			store.dispatch(load()).then(checkAuth);
		} else {
			checkAuth();
		}
	};
Ejemplo n.º 6
0
export const requireLogin = (store, nextState, replace, cb) => {
  function checkAuth() {
    const { auth } = store.getState();
    if (!auth.get('user')) {
      // oops, not logged in, so can't be here!
      let continueTo = nextState.location.pathname + nextState.location.search;
      continueTo = encodeURIComponent(continueTo);
      replace('/login?continueTo=' + continueTo);
    }
    cb();
  }

  if (!isAuthLoaded(store.getState())) {
    store.dispatch(loadAuth())
      .then(checkAuth)
      .catch(checkAuth);
  } else {
    checkAuth();
  }
};