Преглед на файлове

page reload redirect fixed via router tocken auth replacement

= преди 5 години
родител
ревизия
a2c35db19b

+ 0 - 34
src/components/common/input-form.js

@@ -1,34 +0,0 @@
-import React, { Component } from "react";
-import { connect } from "react-redux";
-import { reduxForm, Field, FieldArray } from "redux-form";
-
-const renderField = ({ input, meta: { touched, error }, label, type }) => (
-	<div className="form__input-box">
-		<label className="form__input-lable" htmlFor="origin">
-			{label}
-			<input type={type} {...input} />
-		</label>
-		{touched && error && <span>{error}</span>}
-	</div>
-);
-
-class LoadForm extends Component {
-	
-	render() {
-		const { handleSubmit, title, pristine, submitting } = this.props;
-
-		return (
-			<form onSubmit={handleSubmit(this.submit)} className="form">
-				
-			</form>
-		);
-	}
-}
-
-const mapStateToProps = (state, props) => ({
-});
-
-const component = reduxForm({ })(LoadForm);
-
-export default connect(mapStateToProps)(component);
-

+ 5 - 1
src/components/common/protectedRoute/index.js

@@ -1,13 +1,17 @@
 import React from 'react';
 import { Route, Redirect } from 'react-router-dom';
 
+import token from '../../../utils/token'
+
 import * as routes from './../../../constants/routes';
 import PermissionDenied from './../../public-components/permissionDenied';
 
-export default ({ component: Component, user: {data}, access, ...rest  }) => (
+export default ({ component: Component, user, access, ...rest  }) => (
     <Route
         {...rest}
         render={props => {
+            const storagedUser = JSON.parse(localStorage.getItem(token));
+            const data = user.data || storagedUser || null;
 
             if (access === 'public') {
                 return <Component {...props} />

+ 0 - 6
src/components/common/protectedRoute/validate/index.js

@@ -1,6 +0,0 @@
-export default function validate(values) {
-    const {} = values;
-    const errors = {}
-
-    return errors;
-}

+ 10 - 13
src/router.js

@@ -21,30 +21,27 @@ class Router extends React.Component {
         const storagedUser = localStorage.getItem(fakeToken);
         const { tokenAuth } = this.props;
 
-
         storagedUser && tokenAuth(JSON.parse(storagedUser));
     }
 
     render() {
         const { user } = this.props;
-        
-        //map located here because of switch-bag
-        const Router = config.map(route =>
-            <ProtectedRoute
-                path={route.path}
-                component={route.component}
-                access={route.access}
-                user={user}
-                exact
-            />
-        )
 
         return (
             <div className="app">
                 <Header />
                 <Suspense fallback={<Spinner />}>
                     <Switch>
-                        {Router}
+                        {config.map(route =>
+                            <ProtectedRoute
+                                path={route.path}
+                                component={route.component}
+                                access={route.access}
+                                user={user}
+                                key={route}
+                                exact
+                            />
+                        )}
                     </Switch>
                 </Suspense>
                 <Footer />

+ 13 - 13
src/saga/auth/signIn/index.js

@@ -7,18 +7,18 @@ import token from '../../../utils/token'
 // worker-saga for signing in
 
 export default function* ({ payload: { login, password } }) {
-  try {
-    const payload = yield call(() =>
-      axios.get(`${SIGN_IN_URL}login=${login}&password=${password}`)
-        .then(({ data: [payload] }) => payload)
-    );
+    try {
+        const payload = yield call(() =>
+            axios.get(`${SIGN_IN_URL}login=${login}&password=${password}`)
+                .then(({ data: [payload] }) => payload)
+        );
 
-    yield call(() => { if (!payload) throw (new Error("No such email or password")) });
-    yield put(actions.signInRequestSucces(payload));
-    yield call(() => localStorage.setItem(token, JSON.stringify(payload)));
-  }
-  catch ({ message }) {
-    yield put(actions.signInRequestFailure(message));
-    yield call(() => localStorage.removeItem(token));
-  }
+        yield call(() => { if (!payload) throw (new Error("No such email or password")) });
+        yield put(actions.signInRequestSucces(payload));
+        yield call(() => localStorage.setItem(token, JSON.stringify(payload)));
+    }
+    catch ({ message }) {
+        yield put(actions.signInRequestFailure(message));
+        yield call(() => localStorage.removeItem(token));
+    }
 }