Hi @BohdanYavorskyi, and sorry for the late reply!
You could create a custom API endpoint, such as /api/auth/validate-session, that you can use to send the current session to the backend side of your NextJS application. Then, you can call the Management API to check the user’s active session and redirect to the logout if the session is terminated.
Regarding the ‘login-required’ error, we have a knowledge article on that topic, if you would like some help with it.
Please let me know if I can be of more assistance.
Teodor.