Keep track of connected devices and log them out

How to manage connected devices and be able to log out of a specific device like wappler website?

Could you rephrase?

Are you trying to create a website where you can go into an admin panel and log out users who are currently logged in?

Or what?

In apps like Netflix, Spotify and Wappler itself, you are able to disconnect your account connected to other devices.

Example:

I logged in with my account on “Device 1” and then logged in with the same account on “Device 2”.

How can I disconnect “Device 1” through “Device 2”?

I don’t know of a tutorial.
And, I don’t really know how Wappler does cookies.

If you can learn cookie stuff in Wappler then you can apply this.

Before Wappler I would’ve used PHP.

In PHP I would probably add “RandomCode” and “RandomCodeValid” to a new table; probably “UserLogins” or something in my DB. And I’d store some other things that told me about the computer so users could know which login was which: “BrowserName” and “IPlocation” - “TimeOfLastLogin” etc.

Then, whenever a user came to my site I’d check to see if “RandomCodeValid” == 1 in the DB.
If it did, let them head on in.

But, I’d let users have a “log out” piece where they could log out certain devices. If they did, then I’d set “RandomCodeValid” == 0

> <?php
> //Assign a random code that will be between 7 digits and 9 digits (millions of possibilities)
> $RandomCode = rand(1000000,999999999);
> 
> //Insert it in the DB
> 
> // Setting a cookie
> setcookie("UserDeviceCode", $RandomCode, time()+30*24*60*60);
> ?>

Unfortunately, I don’t know how to do that in Wappler right now.
Someone else may be able to help.
Or maybe that’s enough to get you started once you do your own Cookie research in Wappler.

I don’t believe cookies will work. Cookies are stored on individual devices. If you log in with your phone for example, you can’t clear the cookie on your laptop. You can only clear the cookies on the device you are using at the time.

That’s why you store the code sent to the cookie in your DB.

1 Like

In node it could probably be done via sockets with an emit, other languages will be more difficult needing some code to force a logout probably via a global server action as kit is called with every API call

First of all the community forum is not powered by Wappler, but by discourse.

Also this could be quite a complex thingy as it depends on the server model and requires some custom code as you need to destroy server sessions that could be stored in different type of stores(memory, redis, database, etc).

Also if you want to logout automatically a user from the frontend whenever the server session is destroyed you need to do it via websocket(exclusive to nodejs) as @Hyperbytes mentioned.

Can it be done? Yes. Is it trivial? No. I believe you are at the beginning of your Wappler learning journey. So unless this is a critical thing for your app I would advise to leave it for the future with the peace of mind of knowing that it can be done.

I managed to do with the fingerprintjs library https://github.com/fingerprintjs/fingerprintjs

thank you all