title: Disconnect function in NEXTJS (server side)
body: <p>I need to create a connected device limiter for my next.js application. When the user accesses the website, logged in, a function is executed that adds him to the list of connected users. Each user can have one device connected, only. If the person tries to access the app logged into the same account on another device, a waiting screen is displayed. So far, everything is beautiful. The problem is: when the person disconnects. Whatever the reason, if a connection is lost, a function that removes it from the list of connected users must be executed on the server side.</p>
  <pre class="lang-js prettyprint-override"><code>
  export const getServerSideProps = async (ctx) =&gt; {
    // get cookies
    // database
    
    if(connected.includes(user)) {
      // Displays the waiting screen
      // When he leaves the list, he asks if he wants to connect the device.
    }
    
    if(!connected.includes(user)){
      // Add user to the connected list
    }
    
    user.onDisconnect = disconnect()
    // For example, it doesn't have to be inside getServerSideProps.
  }
  
  function disconnect () {
    // Remove user from the connected list
  }
  
  
  </code></pre>
  <p>Is there any method of doing this <strong>without</strong> <em>socket.io</em>?</p>