nathvarun gave a very complete answer, but I’d like to share the steps I do for authentication in my app.
- Send
email+passwordvia ajax to the server - Generate a
tokenin the server and send it back to the app - Store
email+tokeninlocalStorage - For every single request I make to the server I send
email+tokenviaPOST - In the server I verify authenticity of that user with that token, if
truethe method is executed, iffalseI send back to the app an error (401) - If app receives success, then it’s ok, if receives error I redirect to login screen.
Nice thing is that when the app is open, you can get the email + token from localStorage, send to the server, if that token is ok for that user, redirect to main screen, otherwise redirect to login. Then whenever user clears the cache of the app, he is redirected to login screen.