Seems rather simple question but I can’t get it worked.
How to know through REST API whether a user is already logged in from another device?
I have disabled ‘allow multiple logins’ so if a user logs in from another device first device is logged out.
But what I want is, when a user tries to log in with the first I will check if the same user is already logged in from another device, if yes then I can notify user that “same user is already logged in from another device and will be logged out”
You could create a custom server side code to do the login process.
To login, you’ll send you login information (email, password) PLUS a deviceID hash.
You can then evaluate in your server code if the deviceId the user sends is similar to the existing one (in the userObject). You’ll also need to extend the userObject with that deviceID field.
You will then be able to tell the user if he was logged in on another device + can return the actual user object.
Hope I understood your problem correctly.
Let me know if this approach does the trick.
Thanks for the reply.
Yes you are right, what I want is ‘when SECOND user logins - notify SECOND user and logout the FIRST.’
Hi Jens,
This solutions seems workable but currently, I don’t know much about server side code.
Would definitely explore this after learning how server side code works in my scenerio.
I am currently developing app in pure ActionScript 3 user Backendless with REST API.
Apparently you need some custom business logic here. If I were you I would do following:
Use after login handler to store user tokens and user data in your custom table
Use before login handler to query existing user token from your table
If user token exists you check whether token is valid
If token is valid you notify user that session would be interrupted
Backendless would automatically logout first user if you had chosen first multiple login scheme
…
PROFIT!
Please, notify us if need more detailed explanation or help with Java.