0

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.


export const getServerSideProps = async (ctx) => {
  // 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
}


Is there any method of doing this without socket.io?

1 Answers1

0

I was looking at Pusher and I think it might be a good way to solve my problem. Any suggestion?