Get 2024 Templates Mega Bundle!$1000 worth of 19 Bootstrap HTML, Vue & React Templates + 3 Vector Sets for just $99
Get for 99$

Metronic 8 Boostrap Vue theme


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();
}


And the behavior the the user is
1. going to the page
2. verify auth
3. fails
4. page loads
5. click menu to go to another page
6. redirect to sign-in

I would like to be redirected to sing-in straight away.
I've changed the verifyAuth() method to


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();
}
}


it works but I can see the page that I`m going to for a while and then redirect to login page. Can I have better experience?

regards for all KTTeam!

Krystian


Text formatting options
Submit
Here's a how to add some HTML formatting to your comment:
  • <pre></pre> for JS codes block
  • <pre lang="html"></pre> for HTML code block
  • <pre lang="scss"></pre> for SCSS code block
  • <pre lang="php"></pre> for PHP code block
  • <code></code> for single line of code
  • <strong></strong> to make things bold
  • <em></em> to emphasize
  • <ul><li></li></ul>  to make list
  • <ol><li></li></ol>  to make ordered list
  • <h3></h3> to make headings
  • <a></a> for links
  • <img> to paste in an image
  • <blockquote></blockquote> to quote somebody
  • happy  :)
  • shocked  :|
  • sad  :(

Replies (3)

Deleted comment

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


Text formatting options
Submit
Here's a how to add some HTML formatting to your comment:
  • <pre></pre> for JS codes block
  • <pre lang="html"></pre> for HTML code block
  • <pre lang="scss"></pre> for SCSS code block
  • <pre lang="php"></pre> for PHP code block
  • <code></code> for single line of code
  • <strong></strong> to make things bold
  • <em></em> to emphasize
  • <ul><li></li></ul>  to make list
  • <ol><li></li></ol>  to make ordered list
  • <h3></h3> to make headings
  • <a></a> for links
  • <img> to paste in an image
  • <blockquote></blockquote> to quote somebody
  • happy  :)
  • shocked  :|
  • sad  :(
Text formatting options
Submit
Here's a how to add some HTML formatting to your comment:
  • <pre></pre> for JS codes block
  • <pre lang="html"></pre> for HTML code block
  • <pre lang="scss"></pre> for SCSS code block
  • <pre lang="php"></pre> for PHP code block
  • <code></code> for single line of code
  • <strong></strong> to make things bold
  • <em></em> to emphasize
  • <ul><li></li></ul>  to make list
  • <ol><li></li></ol>  to make ordered list
  • <h3></h3> to make headings
  • <a></a> for links
  • <img> to paste in an image
  • <blockquote></blockquote> to quote somebody
  • happy  :)
  • shocked  :|
  • sad  :(