Skip to content

Commit e6f5c57

Browse files
Merge pull request #6 from app-generator/dev
Fix / logout button fixes
2 parents 05eaa96 + 5defda8 commit e6f5c57

File tree

5 files changed

+54
-35
lines changed

5 files changed

+54
-35
lines changed

src/config/constant.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
11
export const API_SERVER = "http://localhost:5000/api/";
2-
// export const API_SERVER = "https://api-server-nodejs.appseed.us/api/";

src/examples/Navbars/DashboardNavbar/index.js

Lines changed: 2 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Coded by www.creative-tim.com
1616
import { useState, useEffect } from "react";
1717

1818
// react-router components
19-
import { useLocation, Link } from "react-router-dom";
19+
import { useLocation } from "react-router-dom";
2020

2121
// prop-types is a library for typechecking of props.
2222
import PropTypes from "prop-types";
@@ -30,9 +30,7 @@ import Icon from "@mui/material/Icon";
3030

3131
// Soft UI Dashboard React components
3232
import SuiBox from "components/SuiBox";
33-
import SuiTypography from "components/SuiTypography";
3433
import SuiInput from "components/SuiInput";
35-
import Cube from "examples/Icons/Cube";
3634

3735
// Soft UI Dashboard React example components
3836
import Breadcrumbs from "examples/Breadcrumbs";
@@ -48,20 +46,14 @@ import { useSoftUIController } from "context";
4846
import team2 from "assets/images/team-2.jpg";
4947
import logoSpotify from "assets/images/small-logos/logo-spotify.svg";
5048

51-
import { useAuth } from "../../../auth-context/auth.context";
52-
import { useHistory } from "react-router-dom";
53-
import AuthApi from "../../../api/auth";
54-
5549
function DashboardNavbar({ absolute, light, isMini }) {
5650
const [navbarType, setNavbarType] = useState();
5751
const [controller, dispatch] = useSoftUIController();
5852
const { miniSidenav, transparentNavbar, fixedNavbar, openConfigurator } = controller;
5953
const [openMenu, setOpenMenu] = useState(false);
6054
const classes = styles({ transparentNavbar, absolute, light, isMini });
6155
const route = useLocation().pathname.split("/").slice(1);
62-
const { setUser } = useAuth();
63-
let { user } = useAuth();
64-
const history = useHistory();
56+
6557
useEffect(() => {
6658
// Setting the navbar type
6759
if (fixedNavbar) {
@@ -97,13 +89,6 @@ function DashboardNavbar({ absolute, light, isMini }) {
9789
const handleOpenMenu = (event) => setOpenMenu(event.currentTarget);
9890
const handleCloseMenu = () => setOpenMenu(false);
9991

100-
const handleLogout = async () => {
101-
await AuthApi.Logout(user);
102-
await setUser(null);
103-
localStorage.removeItem("user");
104-
return history.push("/authentication/sign-in");
105-
};
106-
10792
// Render the notifications menu
10893
const renderMenu = () => (
10994
<Menu
@@ -166,20 +151,6 @@ function DashboardNavbar({ absolute, light, isMini }) {
166151
color={light ? "white" : "inherit"}
167152
customClass={classes.navbar_section_desktop}
168153
>
169-
<Link to="#">
170-
<IconButton onClick={handleLogout} className={classes.navbar_icon_button}>
171-
<Icon className={light ? "text-white" : "text-dark"}>
172-
<Cube size="12px" />
173-
</Icon>
174-
<SuiTypography
175-
variant="button"
176-
fontWeight="medium"
177-
textColor={light ? "white" : "dark"}
178-
>
179-
Sign Out
180-
</SuiTypography>
181-
</IconButton>
182-
</Link>
183154
<IconButton
184155
size="small"
185156
color="inherit"

src/layouts/authentication/sign-in/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ function SignIn() {
6363
if (password === "") {
6464
return setError("You must enter your password");
6565
}
66+
setButtonText("Signing in");
6667
try {
6768
let response = await AuthApi.Login({
6869
email,
@@ -71,7 +72,6 @@ function SignIn() {
7172
if (response.data && response.data.success === false) {
7273
return setError(response.data.msg);
7374
}
74-
setButtonText("Signing in");
7575
return setProfile(response);
7676
} catch (err) {
7777
console.log(err);
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/**
2+
=========================================================
3+
* Soft UI Dashboard React - v2.0.0
4+
=========================================================
5+
6+
* Product Page: https://www.creative-tim.com/product/soft-ui-dashboard-material-ui
7+
* Copyright 2021 Creative Tim (https://www.creative-tim.com)
8+
9+
Coded by www.creative-tim.com
10+
11+
=========================================================
12+
13+
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
14+
*/
15+
import { useEffect } from "react";
16+
import AuthApi from "../../../api/auth";
17+
import { useHistory } from "react-router-dom";
18+
import { useAuth } from "../../../auth-context/auth.context";
19+
20+
function SignOut() {
21+
const history = useHistory();
22+
const { setUser } = useAuth();
23+
let { user } = useAuth();
24+
25+
const handleLogout = async () => {
26+
await AuthApi.Logout(user);
27+
await setUser(null);
28+
localStorage.removeItem("user");
29+
return history.push("/authentication/sign-in");
30+
};
31+
32+
useEffect(() => {
33+
handleLogout();
34+
}, []);
35+
36+
return null;
37+
}
38+
39+
export default SignOut;

src/routes.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ import RTL from "layouts/rtl";
4444
import Profile from "layouts/profile";
4545
import SignIn from "layouts/authentication/sign-in";
4646
import SignUp from "layouts/authentication/sign-up";
47+
import SignOut from "layouts/authentication/sign-out";
4748

4849
// Soft UI Dashboard React icons
4950
import Shop from "examples/Icons/Shop";
@@ -118,7 +119,7 @@ const routes = [
118119
protected: true,
119120
},
120121
{
121-
type: "collapse",
122+
type: "none",
122123
name: "Sign In",
123124
key: "sign-in",
124125
route: "/authentication/sign-in",
@@ -127,14 +128,23 @@ const routes = [
127128
noCollapse: true,
128129
},
129130
{
130-
type: "collapse",
131+
type: "none",
131132
name: "Sign Up",
132133
key: "sign-up",
133134
route: "/authentication/sign-up",
134135
icon: <SpaceShip size="12px" />,
135136
component: SignUp,
136137
noCollapse: true,
137138
},
139+
{
140+
type: "collapse",
141+
name: "Logout",
142+
key: "sign-out",
143+
route: "/authentication/sign-out",
144+
icon: <SpaceShip size="12px" />,
145+
component: SignOut,
146+
noCollapse: true,
147+
},
138148
];
139149

140150
export default routes;

0 commit comments

Comments
 (0)