Got the solution from another thread Check session without extending it. We can do like this:-
getAccessTokenSilently()
.then((token) => {
console.log(token);
})
.catch((e) => {
if (e.error === "login_required")
alert("logging out");
});
Thanks