Skip to content

Commit

Permalink
logout actually logs out and redirects to index page
Browse files Browse the repository at this point in the history
  • Loading branch information
LG9757 committed Apr 26, 2024
1 parent d7c15df commit 7ddb7c9
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
11 changes: 9 additions & 2 deletions src/components/Header.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import useWindowDimensions from "../hooks/WindowDimensionsHook.tsx";
import "../assets/css/Header.css"
import {Link} from "react-router-dom";
import {Link, useNavigate} from "react-router-dom";
import {auth} from "../utils/firebase.ts";

interface Props {
Expand All @@ -15,6 +15,13 @@ export function Header({ user }: Props) {

const currentUser = auth.currentUser?.displayName?? "";

const navigate = useNavigate();

const handleLogout = () => {
auth.signOut();
navigate("/", { replace: true });
};

return (
<header className="header">
{/* App Name reloads home page */}
Expand All @@ -35,7 +42,7 @@ export function Header({ user }: Props) {
{user && (
<li>
<span className="username">{currentUser}</span>
<button type="button" className="logout-btn">Logout</button>
<button type="button" className="logout-btn" onClick={handleLogout}>Logout</button>
</li>
)}
</ul>
Expand Down
2 changes: 1 addition & 1 deletion src/router.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ const tileset_weird: Array<{ text: string; rows: number; cols: number }> = [
export const router = createBrowserRouter([
{
path: "/",
element: <IndexPage />, // Remove the user={undefined} prop
element: <IndexPage />,
errorElement: <_404Page/>
},
{
Expand Down

0 comments on commit 7ddb7c9

Please sign in to comment.