diff --git a/diskuy/src/LoginForm.js b/diskuy/src/LoginForm.js index 65f522ecec7aab6e6e13ca5d6a6141dccf6de019..72753025e03a0b6a6da4fb4def01af4d9958d3bb 100644 --- a/diskuy/src/LoginForm.js +++ b/diskuy/src/LoginForm.js @@ -28,7 +28,8 @@ export default function LoginForm(props){ try { await AuthService.login(username, password) - props.history.push('/topics') + props.history.push('/') + window.location.reload() } catch(error) { const responseMessage = diff --git a/diskuy/src/Navbar.js b/diskuy/src/Navbar.js index 1dcb814db18d926e33e70a668e692532aad8459c..793d8e222425da4d0e3dcad112aeb03384006547 100644 --- a/diskuy/src/Navbar.js +++ b/diskuy/src/Navbar.js @@ -1,11 +1,20 @@ import React from "react"; import {ReactComponent as DiskuyLogo} from './Logo.svg'; import './Navbar.css'; +import { useState } from "react"; +import AuthService from './services/auth.service' import { Link } from "react-router-dom" const Navbar = () => { + const [loggedIn, setLoggedIn] = useState(AuthService.getCurrentUser() && 1) + + const handleLogout = (event) => { + AuthService.logout() + setLoggedIn(false) + window.location.reload() + } return ( <nav id = "navbar" className='navbar navbar-expand-lg navbar-light position-sticky fixed-top'> <div className="navbar-brand"> @@ -20,6 +29,11 @@ const Navbar = () => { <li className="nav-item ml-auto"> <Link to="/profile" className="nav-link"><b>Profile</b></Link> </li> + {loggedIn && ( + <li className='nav-item ml-auto' onClick={handleLogout}> + <Link to='/login' className='nav-link'><b>Logout</b></Link> + </li> + )} </ul> </nav> ); diff --git a/diskuy/src/RegisterForm.js b/diskuy/src/RegisterForm.js index 8ad564dddc594189f8efba9ead3a9cae49322653..6a128318c0ee9cffe69b14cb3ee2cebf523e20d0 100644 --- a/diskuy/src/RegisterForm.js +++ b/diskuy/src/RegisterForm.js @@ -30,7 +30,8 @@ export default function RegisterForm(props){ const response = AuthService.register(username, email, password) setMessage(response.data.message) setSuccesful(true) - props.history.push('/topics') + props.history.push('/') + window.location.reload() } catch(error){ const responseMessage =