Try to use data in the cache to verify that the user is already inside or already logged in.
you can use the local storage
There is already a JS who does all the work.
link
With this you can keep data in your browser as long as the navigation history cache is not cleaned
implementation
// set Cookie
amplify.storage ("myvar", '{"id": "1234", "name": "jose", "session": true}');
//get Cookie
amplify.storage("myvar");
and you can make a validation to see if it is logged in
if (amplify.storage ("myvar")! = undefined) {
enter_main ();
} else {
ir_loggin ();
}