Logout of all Tabs : Multi-tab logout React 2022

แชร์
ฝัง
  • เผยแพร่เมื่อ 14 ม.ค. 2025

ความคิดเห็น • 5

  • @kc-hz3sp
    @kc-hz3sp 2 ปีที่แล้ว +1

    This was really useful and straightforward. Thanks

  • @kapiljain4423
    @kapiljain4423 ปีที่แล้ว

    hi, how to logout when closed the broswer. can you please upload a video on that. i am usins redux state management to store token.

    • @demawocodes
      @demawocodes  ปีที่แล้ว

      Hi you can use a function like this ======>
      // Set the amount of time before the user is logged out (in milliseconds)
      const LOGOUT_TIME = 300000; // 5 minutes
      let timer; // Declare the timer variable
      // Function to reset the timer
      function resetTimer() {
      clearTimeout(timer);
      timer = setTimeout(logout, LOGOUT_TIME);
      }
      // Function to logout the user
      function logout() {
      // Perform the logout operation
      console.log("User has been logged out due to inactivity.");
      }
      // Add event listeners to monitor user interaction
      document.addEventListener("mousemove", resetTimer);
      document.addEventListener("keypress", resetTimer);
      // Start the timer
      resetTimer();
      So basically the function logs out a user if there in no activity.

    • @kapiljain4423
      @kapiljain4423 ปีที่แล้ว +1

      @@demawocodes thanks very useful

  • @thrifterspoint1002
    @thrifterspoint1002 7 หลายเดือนก่อน

    its better u dont loggedIn user when he/she already loggedin