From 0d92da9446f40d505bf92103b786a4cffdf98e99 Mon Sep 17 00:00:00 2001 From: sushant dhimal Date: Thu, 16 Mar 2023 14:25:52 +0545 Subject: [PATCH] add: logout functionality in larger devices - add logout functionality in devices with width > 1024px --- client/src/components/NavLink.jsx | 21 ++++++++++++++++++--- client/src/context/AuthReducer.js | 5 +++++ client/src/pages/Home.jsx | 22 ++++++++++++++++++++++ 3 files changed, 45 insertions(+), 3 deletions(-) diff --git a/client/src/components/NavLink.jsx b/client/src/components/NavLink.jsx index 6ec55d5..c53eaf1 100644 --- a/client/src/components/NavLink.jsx +++ b/client/src/components/NavLink.jsx @@ -1,13 +1,28 @@ -import React from "react"; +import React, { useContext } from "react"; +import { signOut } from "firebase/auth"; +import { auth } from "../firebase.config"; +import { AuthContext } from "../context/AuthContext"; const NavLinks = ({ svg, link, text, setChatLog }) => { - const handleClick = (text) => { + const { dispatch } = useContext(AuthContext); + + const handleClick = async (text) => { if (text === "Clear Conversations") setChatLog([]); + if (text === "Log out") { + try { + let logOut = await signOut(auth); + console.log("logOut", logOut); + dispatch({ type: "LOGOUT" }); + } catch (error) { + console.log("error happen during sign out", error); + } + } }; + return ( handleClick(text)} diff --git a/client/src/context/AuthReducer.js b/client/src/context/AuthReducer.js index 2ef33d5..fa51796 100644 --- a/client/src/context/AuthReducer.js +++ b/client/src/context/AuthReducer.js @@ -12,6 +12,11 @@ function AuthReducer(state, action) { currentUser: action.payload, }; } + case "LOGOUT": { + return { + currentUser: "", + }; + } default: { return state; } diff --git a/client/src/pages/Home.jsx b/client/src/pages/Home.jsx index e4640df..c666ddc 100644 --- a/client/src/pages/Home.jsx +++ b/client/src/pages/Home.jsx @@ -91,6 +91,7 @@ const Home = () => {

TalkBot

+ {showMenu && (