Force user to redirect if he is logged in

Hi guys,
I have a login page and server action “login” which uses Security Provider to log in user based on email and password.
On the client side, I use Dynamic event to redirect user on Success to the Home page.
Pretty standard stuff.

The problem.
If user is logged in and goes to /login page, he still see login form. He can fill it and log in again. Everything works, but this is not the most desired logic.
Should be: if user is logged in and goes to /login page, he is redirected to /home page.

Question. How to do this redirect if user is logged in?
How can it be done on the client side? I call server action only after user is pressing “login” button, but redirect should be done if he is just opening this page.

Thanks!

Community Page
Last updated: