From 612f96a9c582b3bf975417540eaa8e344563b86c Mon Sep 17 00:00:00 2001 From: Miguel de la Cruz Date: Mon, 13 Sep 2021 11:24:36 +0200 Subject: [PATCH] Rename user context as token context and move to a global context.js --- webapp/src/context.js | 3 +++ webapp/src/index.js | 18 +++++++++--------- webapp/src/pages/home.js | 4 ++-- webapp/src/pages/login.js | 4 ++-- webapp/src/user-context.js | 5 ----- 5 files changed, 16 insertions(+), 18 deletions(-) create mode 100644 webapp/src/context.js delete mode 100644 webapp/src/user-context.js diff --git a/webapp/src/context.js b/webapp/src/context.js new file mode 100644 index 0000000..abbd8c4 --- /dev/null +++ b/webapp/src/context.js @@ -0,0 +1,3 @@ +import React from 'react' + +export const TokenContext = React.createContext() diff --git a/webapp/src/index.js b/webapp/src/index.js index e76c70b..a5fa1b9 100644 --- a/webapp/src/index.js +++ b/webapp/src/index.js @@ -10,13 +10,13 @@ import { import { CssBaseline } from '@material-ui/core'; -import UserContext from './user-context' +import { TokenContext } from './context' import Login from './pages/login' import Home from './pages/home' const Secure = ({children}) => { - const { token } = useContext(UserContext) + const { token } = useContext(TokenContext) if (!token) { return } @@ -28,10 +28,10 @@ const App = () => { const [token, setToken] = useState(localStorage.getItem('token')) return ( - - - - + + + + @@ -41,9 +41,9 @@ const App = () => { - - - + + + ) } diff --git a/webapp/src/pages/home.js b/webapp/src/pages/home.js index 84b337d..043c4fa 100644 --- a/webapp/src/pages/home.js +++ b/webapp/src/pages/home.js @@ -4,11 +4,11 @@ import { Button } from '@material-ui/core'; -import UserContext from '../user-context' +import { TokenContext } from '../context' const Home = () => { - const { token, setToken } = useContext(UserContext) + const { token, setToken } = useContext(TokenContext) const handleLogout = (e) => { e.preventDefault() diff --git a/webapp/src/pages/login.js b/webapp/src/pages/login.js index 25d94c7..7f5688a 100644 --- a/webapp/src/pages/login.js +++ b/webapp/src/pages/login.js @@ -7,10 +7,10 @@ import { } from '@material-ui/core'; import client from '../client' -import UserContext from '../user-context' +import { TokenContext } from '../context' const Login = () => { - const { token, setToken } = useContext(UserContext) + const { token, setToken } = useContext(TokenContext) if (token) { return diff --git a/webapp/src/user-context.js b/webapp/src/user-context.js deleted file mode 100644 index d254589..0000000 --- a/webapp/src/user-context.js +++ /dev/null @@ -1,5 +0,0 @@ -import React from 'react' - -const UserContext = React.createContext() - -export default UserContext