How to prevent user for Multi login at same time

0 votes

Now, in my app, same user can login from multiple devices at same time, i want to prevent user to multi login at same time, means one user can login only once, if same time he tries to login from another devices, he will not able to login and shows him, "You already loged in from another device" or something else.

 

How to achieve this?

 

Thanks!

asked Oct 8, 2014 in App42 Cloud API-BaaS by shivdataservices (30 points) 1 flag
Thanks man, really helpful..

:)

1 Answer

0 votes
 
Best answer

Hello Shiv,

Once use authentication is success, you will get a session Id too in User object. You can use session service and set a flag in the session attribute afterlogin against that sessionId.

If you want to check user is already logged in or not you can check it from session service using Get Attribute method.

Make sure you call logout method on user service once use is logged out/close the app so that he can login from other device.

Thanks

answered Oct 8, 2014 by hs00105 (2,005 points)
selected Oct 10, 2014 by shivdataservices
Please give me link of any android example related this issue.

Thanks.
Hello Shiv,
 
Please find a link below which has sample project which handles this scenario. This has been demonstrated  using two buttons in the sample UI.
 
On first button click, "Login or Register" your user will register on App42. On the basis of his session id, we save user loginStatus attribute in session service.
 
When you click on second button, first it see if loginStatus is set in current session or not, if it is set it will throw the exception stating user is already logged in on another device. Below is download link for the same.

 
http://cdn.shephertz.com/repository/files/7a6b25fc1d82dc1e1d614466a1c549a6e24f4a6b9c32fbded52c0ea224b9cbc4/7a6d236b5ad6e6753f0f8710ae021900df28a403/samplezip.zip
 
Please check and let us know if it helps.
 
Thanks,
Himanshu Sharma
Thanks man, really helpful..

:)
how about appwarp S2? what should i do?
Hi hs00105

if app not close normal way or disconnect internet then close app, session not remove from server and app cant send anything to server for change on it , so user cant login again because session or every other parameter not change on server.

i search in forum and not find any correct answer for this problem. for example your answer in below link not correct.
main problem is that we cant never be sure user logged out and change session attribute or update json document.

http://forum.shephertz.com/?qa=1855/only-one-user-can-login-with-authenticate-at-the-same-time
Download Widgets
Welcome to ShepHertz Product line forum, where you can ask questions and receive answers from the community. You can also reach out to us on support@shephertz.com
...