Forráskód Böngészése

remember token in sessionStorage and edit authReducer and function qetGqL

makstravm 3 éve
szülő
commit
4a982a9ea3
6 módosított fájl, 30 hozzáadás és 17 törlés
  1. 5 5
      src/App.js
  2. 8 1
      src/App.scss
  3. 2 1
      src/helpers/index.js
  4. 0 4
      src/pages/Authorization.jsx
  5. 10 3
      src/pages/Content.js
  6. 5 3
      src/redux/auth-reducer.js

+ 5 - 5
src/App.js

@@ -19,14 +19,14 @@ const AppContent = ({ isToken }) =>
             <Switch>
                 <Route path='/auth/:_id'
                     component={Authorization} />
-    
                 <Redirect from='/*' to='/auth/login' />
             </Switch>
             :
-            <Switch>
-                <Route path='/' component={Content} exact />
-                <Redirect from='/*' to='/' />
-            </Switch>
+            <Content />
+            // <Switch>
+            //     <Route path='/' component={Content} exact />
+            //     <Redirect from='/auth/*' to='/' />
+            // </Switch>
         }
     </Router >
 

+ 8 - 1
src/App.scss

@@ -83,7 +83,7 @@ select {
     }
     &__form {
         height: 100vh;
-        padding-right:calc(10vw + 25px)
+        padding-right: calc(10vw + 25px);
     }
     .login-form {
         text-align: center;
@@ -92,3 +92,10 @@ select {
         }
     }
 }
+.qq {
+    display: flex;
+    justify-content: space-between;
+    div {
+        width: 50%;
+    }
+}

+ 2 - 1
src/helpers/index.js

@@ -18,7 +18,8 @@ const getGQL = url =>
             method: 'POST',
             headers: {
                 "Content-Type": "application/json",
-                Authorization: localStorage.authToken ? 'Bearer ' + localStorage.authToken : {},
+                ...(localStorage.authToken ? { Authorization: 'Bearer ' + localStorage.authToken } :
+                    sessionStorage.authToken ? { Authorization: 'Bearer ' + sessionStorage.authToken } : {})
             },
             body: JSON.stringify({ query, variables })
         })

+ 0 - 4
src/pages/Authorization.jsx

@@ -53,10 +53,6 @@ const FormInput = ({ buttonTitle, onSignIn }) => {
             <Form.Item
                 name="remember"
                 valuePropName="checked"
-                wrapperCol={{
-                    offset: 8,
-                    span: 16,
-                }}
             >
                 <Checkbox>Remember me</Checkbox>
             </Form.Item>

+ 10 - 3
src/pages/Content.js

@@ -1,5 +1,6 @@
 import React, { useEffect } from 'react'
 import { connect } from 'react-redux'
+import { Route, Switch } from 'react-router-dom'
 import { myFolowingPosts } from '../actions'
 import Header from '../components/header/Header'
 import { CMainContent } from '../components/main/MainContent'
@@ -7,18 +8,24 @@ import { CMainContent } from '../components/main/MainContent'
 
 
 const Main = ({ children }) =>
-    <>{children}</>
+    <div className='qq'>{children}</div>
 
 
 export const CMain = connect(null, { postsFollowing: myFolowingPosts })(Main)
 
+const Aside = () =>
+    <div>sdfsdgsgsdg</div>
+
 export const Content = () => {
     return (
         <>
             <Header />
             <Main>
-                <CMainContent />
-                {/* <Aside /> */}
+                <Switch>
+                    <CMainContent />
+                    <Route path='/message' componernt={Aside} />
+                </Switch>
+
             </Main>
         </>
     )

+ 5 - 3
src/redux/auth-reducer.js

@@ -3,14 +3,16 @@ import { jwtDecode } from '../helpers'
 
 export const authReducer = (state, { type, token, remember }) => {
     if (!state) {
-        if (localStorage.authToken) {
+        if (localStorage.authToken || sessionStorage.authToken) {
             type = 'AUTH_LOGIN'
-            token = localStorage.authToken
+            token = localStorage.authToken || sessionStorage.authTokenauth
         } else state = {}
     }
 
     if (type === 'AUTH_LOGIN') {
-        remember && localStorage.setItem('authToken', token)
+        remember ?
+            localStorage.setItem('authToken', token) :
+            sessionStorage.setItem('authToken', token)
         let payload = jwtDecode(token)
         if (typeof payload === 'object') {
             return {