Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixed bug in logout #5

Merged
merged 1 commit into from
Dec 12, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions client/src/components/Logout.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ const Logout = () => {
setCurrentUser(null);

history.push('/');

swal('Goodbye!', 'You have logged out', 'success');
} catch (error) {
console.log('Login Error: ' + error);
}
Expand Down
7 changes: 3 additions & 4 deletions client/src/components/navigation/Navigation.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,10 @@ import { LoginModal } from '../login';
import './Navigation.css';

const Navigation = () => {
const { currentUser, handleLogin } = useContext(AppContext);
const { currentUser } = useContext(AppContext);
const [show, setShow] = useState(false);
const handleClose = () => setShow(false);
const handleShow = () => setShow(true);
const [open, setOpen] = useState(false);

return (
<div>
Expand Down Expand Up @@ -52,7 +51,7 @@ const Navigation = () => {
<Dropdown as={NavItem}>
<Dropdown.Toggle variant="" className="profile-dropdown-nav">
<Image
src={currentUser?.avatar ? currentUser?.avatar : AnonPic}
src={currentUser ? currentUser?.avatar : AnonPic}
height={50}
width={50}
roundedCircle
Expand All @@ -65,7 +64,7 @@ const Navigation = () => {
<Dropdown.Item as="button" onClick={handleShow}>
Log In
</Dropdown.Item>
<Logout />
{currentUser ? <Logout /> : null}
</Dropdown.Menu>
</Dropdown>
<Link to="/sign-up" className="start-trial-link">
Expand Down
2 changes: 1 addition & 1 deletion client/src/context/AppContext.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export const AppContextProvider = ({ children }) => {
const user = sessionStorage.getItem('user');

useEffect(() => {
if (user) {
if (user && !currentUser) {
axios
.get(`/api/users/me`, {
withCredentials: true
Expand Down