Skip to content

Commit

Permalink
Added after login logic
Browse files Browse the repository at this point in the history
  • Loading branch information
hariharan2017 committed Jun 30, 2022
1 parent 2e02095 commit c7a0a76
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 7 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"sass": "^1.52.3"
},
"scripts": {
"start": "react-scripts start",
"start:app": "react-scripts start",
"start:mock": "node ./mock/server.js",
"build": "react-scripts build",
"test": "react-scripts test",
Expand Down
7 changes: 4 additions & 3 deletions src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@ import "./styles/dark.scss"
function App() {
const { theme } = useSelector((state) => state.application.app);
const { loggedIn } = useSelector((state) => state.authentication);

if(!loggedIn) {
history.push("/");
}

return (
<BrowserRouter>
<div className={theme === DARK_MODE ? "app-container dark" : "app-container"}>
Expand All @@ -27,8 +28,8 @@ function App() {
<Routes history={history}>
<Route path="/">
{!loggedIn && <Route index element={<Login />} />}
<Route path="home" element={<Home />} />
<Route path="users" element={<Datagrid />} />
{loggedIn && <Route path="home" element={<Home />} />}
{loggedIn && <Route path="users" element={<Datagrid />} />}
</Route>
</Routes>
</div>
Expand Down
2 changes: 1 addition & 1 deletion src/components/Login/Login.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const Login = () => {
<div>
<input id="password" placeholder="Password" type={"password"} className="input-style" onChange={(event) => onTextChange(event)}/>
</div>
<button className="button-style" onClick={() => {console.log(form); dispatch(actions.login(form))}}>Login</button>
<button className="button-style" onClick={() => {dispatch(actions.login(form))}}>Login</button>
</div>
</div>
);
Expand Down
3 changes: 2 additions & 1 deletion src/components/Sidebar/Sidebar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import "./Sidebar.scss";
import { Link } from "react-router-dom";
import { useDispatch } from "react-redux";
import { actions as appActions } from "../../data/app";
import { actions as authActions } from "../../data/login";

const Sidebar = () => {
const dispatch = useDispatch();
Expand Down Expand Up @@ -56,7 +57,7 @@ const Sidebar = () => {
<AccountBox className="group-item-icon"/>
<div className="group-item-title">Profile</div>
</div>
<div className="group-item">
<div className="group-item" onClick={() => {dispatch(authActions.logout()); window.location.reload();}}>
<Logout className="group-item-icon"/>
<div className="group-item-title">Logout</div>
</div>
Expand Down
1 change: 0 additions & 1 deletion src/data/login/reducers.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ export default (state, action) => {
state = state || { loading: false, error: null, loggedIn: false };
switch (action.type) {
case actionType.AUTHENTICATION_LOGIN:
console.log(action);
return {
...state,
loading: true,
Expand Down

0 comments on commit c7a0a76

Please sign in to comment.