Beginner question: how do I stop my login form from appearing on my home page? #3183
-
Hi I'm starting to learn web development through HTMX and to do so I'm building a simple login flow. I have two page templates, one for pages which don't require users to be authenticated to access, the other for pages which do require authentication. I have a login form on a page which doesn't require users to be authenticated: <body hx-boost="true">
<output id="results">
</output>
<form id="login" action="/lgn" method="post" hx-target="#results">
<label>
Username
<input type="text"
name="username"
id="username"
value=""
autocomplete="username"
required/>
</label>
<label>
Password
<input type="password"
name="password"
id="password"
value=""
autocomplete="current-password"
required/>
</label>
<button type="submit">Submit</button>
</form> If users enter invalid credentials a message gets placed in the "output" section which I'm happy with, and they stay on the login page; otherwise they get redirected to a home page as shown below: http.Redirect(rw, r, "/home", 303) The problem I'm having is that the login form appears on the home page. It looks as though the home page's HTML being put into the target of the form - the output section. It disappears when I refresh the page. I'm not sure what to do about that, can anyone offer any suggestions? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Hey, you likely want to use the HX-Redirect header here, instead of doing a standard HTTP redirection, see the docs about the latter
Hope this helps! |
Beta Was this translation helpful? Give feedback.
Hey, you likely want to use the HX-Redirect header here, instead of doing a standard HTTP redirection, see the docs about the latter
Hope this helps!