+1 vote
by
Hello, decided to write a site where you need to have an admin panel site. But here's the problem, everything was fine until it came to checks having cookies. On the habare, found a piece of code that checks all incoming requests. Ie, if cookies are available, then call next() function, and if they are not, then redirect to the page with authorization. But for some reason redirection does not work, if I go to the address "admin...", "adminsettings" - for example.

Code:
5f55f82ab9e0a984664300.png

5f55f837b0b7d299790858.png



Не могли бы вы объяснить в чем проблема и рассказать подробнее ее решение? Спасибо.
by
alex4answ , formulate your answer.
by
alex4answ , thanks, fixed it, it's working.
by
paste formatted code, don't paste screenshots, geez.

Lazy to understand and read, I think you do not pass authentication, redirects to the administrator, because the user is not authorized -> redirects to a login and so on cyclically

1 Answer

+3 votes
by
The user goes to adminlogin to register. And there your piece of code works, see if there are cookies, no cookies, then send the user to adminlogin. User goes to adminlogin to register. Then your piece of code will ask if there are cookies and no cookies, so it sends the user to adminlogin. User goes to adminlogin to register. Then your piece of code will ask if there are cookies and no cookies, so it sends the user to adminlogin. User goes to adminlogin to register. Then your bit of code gets executed and checks if there are cookies and no cookies, so it sends the user to adminlogin. User goes to adminlogin ....
.... time passes ...

The browser gets tired of it all and stops this fun process.
...