Automatic logout after 5 minutes

Hi, I would like to achieve the following functionality below but not sure what the best way implement it is.

After the user logs in, I would like a 5 minute timer to start in the header on the homepage.
Once the timer reaches 0, i want to create an alert to ask the user if they wish to remain logged in.

If they click yes, the timer will reset to 5 minutes and the process will repeat.
If the user doesn’t respond to the alert within 15 seconds, they are logged out and the app return to the login page.