Open automatically a login form in a modal

Hi, I have a Login form in a modal (modLogin) in the main layout of my home page.
I created a route “/login” pointing to the home page as well (so I can redirect a user to the login form) and I want that when a user visits this route, the modal will open automatically if the user is not logged in and otherwise be redirected to the home page (/) with the modal hidden.
I’ve tried to use the “ready” event in the App (body) element to get it, but I can´t make it work.
The code is the following:


It seems that the identity in the service connect “scUser” is not available at this stage so the modal is displayed even if the user is logged in. What is wrong? Does anyone have a different solution to achieve the goal to redirect a user to the login form in a modal? Thanks

Could you utilise the Modal’s auto show -> show parameter. It’s a boolean - e.g.

div class=“modal fade” id=“modLogin” is=“dmx-bs5-modal” tabindex="-1" show="!scUser.data.identity"

I would use the ondone dynamic event for the scUser component.

You could use an inline flow (or page flow):
condition -> !scUser.data.identity
then -> run modLogin.show()

that way it waits for the SC call to complete before deciding whether to show/not show the login modal. You may also find a preloader component useful to show a spinner while the SC is initially loading.

You could add an else step to run the browser component’s goto to your user’s landing page

1 Like

Thanks Ben and Scalaris for your answers. Ben’s solution works perfect as the ‘Done’ event waits for the SC scUser to finish.
That is my code:


Many thanks!!!