I am trying to build a login system that also checks if the user has confirmed their email. If the serverconnect form receives an “invalid” response, it will trigger a modal for inputting a code sent by email, I think it’s a pretty standard procedure.
the problem is, I couldn’t get the set value “userid” despite having the output ticked. I only get the response 400’s text of “email unconfirmed”. Am I misunderstanding or misusing how response works here?
The response step in server connect stops further executing the server action.
What are you trying to achieve with these steps after the response step?
Oh!! always learning something new. Thanks Teodor!
About the steps, So, I need to retrieve the userid to be used for the email verification process, where the user inputs the code that was sent to their email.
I mean - when you set a response 400 - what needs to be done? If you need to do something else, then probably your logic is not correct and you don’t need to set a status of 400.
I set 400 to trigger dynamic events “invalid” that opens the modal for email verification.
I set 200 in the else clause to trigger “success” event that redirects user to the dashboard.
basically I use it like a condition, which may or may not be a correct use of responses.
Ok but, when you set the response of 400 - what do you expect to happen when the modal opens? What data do you need from your server action and what for?
I only need the response just to open the modal. I need the userid value thereafter.
after the modal opens, user inputs the code and click the submit button, right here, I need the userid value to query and compare the code, and finally update the is_email_confirmed value to 1.
additionaly, as the modal opens, I also do a query using the userid value just to get simple data, so that I can display “email has been sent to {{user.email}}”
I am thinking maybe I shouldn’t use response for something like this. I should just output values and then just using app flow on click instead of dynamic events based on responses
I think you overcomplicated this. Why do you even log the user in and then log out if he’s not confirmed?
Why not filter the query by the email - check the confirmed column - if not confirmed -> set response 400 if confirmed - log them in.
Also, you can get the email value from the login form on the page, no need to return it from the action.