I am using PHP, AJAX, and JS for my PWA development. I want the user's logged-in state to stay persistent when he/she come back to the PWA app. Right now I am doing it via the help of the Access token and saving it in the cookie with HttpOnly via PHP. Defining it here -
- User enters details, and log in to the app.
- That details sent to the PHP backend, via AJAX.
- Backend login code check that details from database and if matched, then code create a random hashed token.
- Backend code save that hash to the cookie with HttpOnly and secure flag.
- User then prompted with a successfully logged-in message.
- When the next time the user comes back to the web app, the server PHP code looks for that login hashed value saved in a cookie and finds the relevant user from Database.
- If a match found, the user successfully logged-in.
So now my concerns are -
- Is this whole process secure and the same as what gets implemented in Industry.
- If not, then what can be the best way to achieve this with security.