Hi Team,
Metronic on every page change is sending verify request to the backend.
// verify auth token before each page change
authStore.verifyAuth();
// before page access check if page requires authentication
if (to.meta.middleware == "auth") {
if (authStore.isAuthenticated) {
next();
} else {
next({ name: "sign-in" });
}
} else {
next();
}
function verifyAuth() {
if (JwtService.getToken()) {
ApiService.setHeader();
ApiService.post("account/verify", { api_token: JwtService.getToken() })
.then(({ data }) => {
setAuth(data);
})
.catch(({ response }) => {
setError(response.statusText);
purgeAuth();
router.push({ name: "sign-in" });
});
} else {
purgeAuth();
}
}
Hi,
I want to apologize for the late reply.
Did you keep the logic in src/router/index.ts?
Make sure that your verify request doesn't get triggered multiple times when an error happens.
Regards,
Lauris Stepanovs,
Keenthemes Support Team
Hi Lauris,
logic in router/index.ts is kept the same.
Only thing in my solution is that the user sees a restricted by auth page for a while and then being redirected. I would like to do this redirection straight away.
again ... regards to you
Hi,
If the user's authentication token doesn't exist or has an invalid format, you can redirect users straight away to sign in page, however, if the user has an invalid token in the correct format stored in local storage then there is no way to verify the token on the client without doing an additional request.
Regards,
Lauris Stepanovs,
Keenthemes Support Team