A
A
Alexander Koregin2020-01-22 19:58:31
css
Alexander Koregin, 2020-01-22 19:58:31

How to properly block access to the route?

I want to block access to unauthorized users.
Wrote this code.

router.beforeEach((to, from, next) => {
  const authUser = localStorage.getItem("auth");
  const profilePages = ["/profile"];
  const orderPaymnetPages = ["/order-payment"];
  const authRequired = !profilePages.includes(to.path);
  const authRequired2 = !orderPaymnetPages.includes(to.path);

  if (authRequired && authRequired2 && !authUser) {
    next("/");
  }
  next();
});

But it throws an error RangeError: Maximum call stack size exceeded.
It is necessary that access to the /profile and /order-payment routes be blocked.
How can I fix it?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
I
Ivan Bogachev, 2019-04-18
@sfi0zy

In the basic version, at the very moment the background image appears, its properties change transform: scale(reduce the size), filter: blur(reduce the blur) and opacity(either make this image appear, or leave the previous background with the preloader). Then it smoothly changes transform: translatedepending on the position of the mouse or something else (the video shows that everything "rides" a little). The main danger that could be waiting is the poor performance of CSS filters, so things can get a bit sluggish.
In a good way, of course, it would be worth writing all this in shaders and instead of screwing transform: translatesomething like fake3d , but that's a completely different story...

A
Aetae, 2020-01-22
@dragonika8

You work in a circle next("/");.
Add to if to.path !== '/'.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question