I have implemented an APP that should allow one device one account which I will pass the uniqueId to Web API to be save alongside with user account row in SQL database. This validation happen on Splash and Authentication screen. The flow as below:
Logic Flow:
Device 1:
- Splash screen: retrieve value from AsyncStorage. If none, proceed to Authentication. If have value, go to #3
- Fill username and password and click Login.
- APP will fetch with web API together with userName, encrypted password and uniqueId retrieved from DeviceInfo module.
- If uniqueId column in SQL is empty, update the column. If have value, compare with uniqueId param. Condition: MATCH-return OK, NOT MATCH-return multiple login alert as exception.
- Fetch promise resolve OK:- Save encrypted userId and userName into AsyncStorage and go to Dashboard
- Fetch promise reject:- Show alert and stay at current screen.
- Notify Web API to clear the uniqueId column and AsyncStorage will clear the token value when user click Logout button
Device 2:
- Follow directly as Device 1
Situation:
User register 1 device or 1 account. So, if user have 2 device, they have to logout device 1 and login on device 2 to prevent the "Multiple Device Login" alert.
Problem:
As user reported Device 2 are lost or stolen. Our admin system will clear the uniqueId column for reported login information. But the real deal is(for Android, not familiar with ios yet); If user is not logout and press HOME button which fake the report, the APP will rest at task manager and use Device 1 to login. So at the end, 2 device can use 1 account.
Inquiry for the best solutions for the faced PROBLEM:
- Do I need to pass the uniqueId everytime the APP will fetch from the Web API to be validated when I will enquiry Web API for data?
- Is it practical to use Headless JS to check with Web API and inform the UI that multiple device alert and automatically logout the current device?
- Any other better ideas?
Most of tutorial or example show the validation as I doing now, but not found yet for situation on my problem.