From 8a15674e4cc88d83b0fa7e0c928285af2e5fc98e Mon Sep 17 00:00:00 2001 From: canove Date: Thu, 14 Jan 2021 07:10:41 -0300 Subject: [PATCH] chore: removed unused export --- frontend/src/context/Auth/AuthContext.js | 11 ++--------- frontend/src/context/Auth/useAuth.js | 17 ++++++++++++++++- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/frontend/src/context/Auth/AuthContext.js b/frontend/src/context/Auth/AuthContext.js index a2ea303..87bd9ae 100644 --- a/frontend/src/context/Auth/AuthContext.js +++ b/frontend/src/context/Auth/AuthContext.js @@ -5,18 +5,11 @@ import useAuth from "./useAuth"; const AuthContext = createContext(); const AuthProvider = ({ children }) => { - const { - loading, - user, - setUser, - isAuth, - handleLogin, - handleLogout, - } = useAuth(); + const { loading, user, isAuth, handleLogin, handleLogout } = useAuth(); return ( {children} diff --git a/frontend/src/context/Auth/useAuth.js b/frontend/src/context/Auth/useAuth.js index cba200c..30b79f9 100644 --- a/frontend/src/context/Auth/useAuth.js +++ b/frontend/src/context/Auth/useAuth.js @@ -1,5 +1,6 @@ import { useState, useEffect } from "react"; import { useHistory } from "react-router-dom"; +import openSocket from "socket.io-client"; import { toast } from "react-toastify"; @@ -69,6 +70,20 @@ const useAuth = () => { })(); }, []); + useEffect(() => { + const socket = openSocket(process.env.REACT_APP_BACKEND_URL); + + socket.on("user", data => { + if (data.action === "update" && data.user.id === user.id) { + setUser(data.user); + } + }); + + return () => { + socket.disconnect(); + }; + }, [user]); + const handleLogin = async user => { setLoading(true); @@ -97,7 +112,7 @@ const useAuth = () => { history.push("/login"); }; - return { isAuth, user, setUser, loading, handleLogin, handleLogout }; + return { isAuth, user, loading, handleLogin, handleLogout }; }; export default useAuth;