adamant-exabyte-92636
10/06/2021, 1:28 PMmysterious-toddler-20573
10/06/2021, 1:28 PMadamant-exabyte-92636
10/06/2021, 1:31 PMbillions-microphone-84331
10/06/2021, 1:34 PMmysterious-toddler-20573
10/06/2021, 1:40 PMbillions-microphone-84331
10/06/2021, 2:06 PMHX-Retarget would make sense. I am currently implementing a middleware for authentication that intercepts all requests on the server before they arrive in the handlers/controllers.
This middleware is activated for restricted resources and it checks the session/cookies and verifies if the current user is authenticated. If that’s not the case, it redirects (303) the user to the homepage.
So let’s say now that I have an admin page on my website that contains a table listing all users. And for each row in the table, there is a <tr hx-target="this"><td>John</td><td hx-delete="/deleteUser/:id">delete</td></tr> to delete the user/row inline. This is a htmx behavior to trigger a DELETE request on the server, and the response is supposed to be empty so that it removes the row from the table.
Now let’s say the session of the user terminates, but the user is still on the page with the table. Then, he clicks the delete button and the middleware intercepts the request. It realizes that the user is not authenticated anymore and executes the redirect to the home page. However, we are in the middle of a htmx request, so in the end, htmx will swap the content of the home page in the <tr>, which is really not what we want.
Having the possibility to retarget the swap to the body here would make sense. It is a really specific example but I am sure there would be other behaviors where it could be handy.billions-microphone-84331
10/06/2021, 2:08 PMHX-Retarget. If anyone has an idea, I would be glad to hear it!late-king-98305
10/06/2021, 2:10 PMauth0-spa-js package), which attempts to re-establish authentication once the page loads. (I'm using the auth event to put the JWT in hx-headers on the body tag.) This works if the browser is refreshed on a public page, but fails when it's refreshed on a must-be-authenticated page (fails with HTTP 422 because of the missing JWT in the header). I imagine that this is a scenario that is pretty common, but my searching hasn't turned up anything. Assuming there is a write-up somewhere, can one of you point me to it?adamant-exabyte-92636
10/06/2021, 2:29 PMHX-Redirect (e.g. response.setHeader("HX-Redirect", url);) to throw the user back to the login page. Could this work for you?billions-microphone-84331
10/06/2021, 2:36 PMHX-Redirect triggers a page reload 😕gorgeous-airport-54386
10/06/2021, 2:39 PMlate-king-98305
10/06/2021, 2:46 PMafterOnLoad to detect it and show it. The state is controlled on the server, but the UI is still interactive. Really cool stuff; I'm digging this framework!mysterious-toddler-20573
10/06/2021, 3:08 PMuser
10/06/2021, 3:10 PM<form hx-confirm="Transfer these items?" hx-post="/url" hx-include="[name='filter'],[name='buildingFilter']" hx-swap="innerHTML" hx-target="#search-results">
<!-- omitted -->
<a hx-get="/url/detailsModal/@item.ID" hx-swap="innerHTML" hx-target="#modal-holder">Details</a>
</form>
I have an hx-get inside of a form tag and it is triggering the hx-confirm. Is this expected?mysterious-toddler-20573
10/06/2021, 3:11 PMunset keyword to undo the attribute:
html
<form hx-confirm="Transfer these items?" hx-post="/url" hx-include="[name='filter'],[name='buildingFilter']" hx-swap="innerHTML" hx-target="#search-results">
<!-- omitted -->
<a hx-confirm="unset" hx-get="/url/detailsModal/@item.ID" hx-swap="innerHTML" hx-target="#modal-holder">Details</a>
</form>user
10/06/2021, 3:11 PMmysterious-toddler-20573
10/06/2021, 3:25 PMbillions-microphone-84331
10/06/2021, 3:57 PMid on one of those elements)?mysterious-toddler-20573
10/06/2021, 4:01 PMhtml
<div hx-swap-oob="innerHTML:body">
<!-- content to swap into the body -->
...
</div>mysterious-toddler-20573
10/06/2021, 4:01 PMmysterious-toddler-20573
10/06/2021, 4:02 PMmysterious-toddler-20573
10/06/2021, 4:02 PMmysterious-toddler-20573
10/06/2021, 4:02 PMbillions-microphone-84331
10/06/2021, 4:07 PMhx-swap-oob could take a selector, I thought oob needed an id somewhere. So yes, it seems to mimic what could be achieved with HX-Retarget. Thanks!mysterious-toddler-20573
10/06/2021, 4:24 PMbillions-microphone-84331
10/06/2021, 4:39 PMmysterious-toddler-20573
10/06/2021, 6:52 PMfresh-controller-36545
10/06/2021, 8:48 PMhx-push-url? What I mean is, when a URL is pushed and the site is reloaded, it would be nice to have the same state again.fresh-controller-36545
10/06/2021, 8:49 PMhx-push-url element and retriggering the wired up HTMX-event.mysterious-toddler-20573
10/06/2021, 10:06 PM