fixed error flash on successful registration before redirect

This commit is contained in:
2026-01-24 15:36:41 +11:00
parent 4dec97def8
commit 4e5b08b62f
3 changed files with 16 additions and 16 deletions

2
go.sum
View File

@@ -8,8 +8,6 @@ git.haelnorr.com/h/golib/hlog v0.10.4 h1:vpCsV/OddjIYx8F48U66WxojjmhEbeLGQAOBG4V
git.haelnorr.com/h/golib/hlog v0.10.4/go.mod h1:+wJ8vecQY/JITTXKmI3JfkHiUGyMs7N6wooj2wuWZbc= git.haelnorr.com/h/golib/hlog v0.10.4/go.mod h1:+wJ8vecQY/JITTXKmI3JfkHiUGyMs7N6wooj2wuWZbc=
git.haelnorr.com/h/golib/hws v0.3.1 h1:uFXAT8SuKs4VACBdrkmZ+dJjeBlSPgCKUPt8zGCcwrI= git.haelnorr.com/h/golib/hws v0.3.1 h1:uFXAT8SuKs4VACBdrkmZ+dJjeBlSPgCKUPt8zGCcwrI=
git.haelnorr.com/h/golib/hws v0.3.1/go.mod h1:6ZlRKnt8YMpv5XcMXmyBGmD1/euvBo3d1azEvHJjOLo= git.haelnorr.com/h/golib/hws v0.3.1/go.mod h1:6ZlRKnt8YMpv5XcMXmyBGmD1/euvBo3d1azEvHJjOLo=
git.haelnorr.com/h/golib/hwsauth v0.5.1 h1:U7rLPWLjPvggcY0Ez8VVIgcueLLHLLUV69OjYv/QepQ=
git.haelnorr.com/h/golib/hwsauth v0.5.1/go.mod h1:NOonrVU/lX8lzuV77eDEiTwBjn7RrzYVcSdXUJWeHmQ=
git.haelnorr.com/h/golib/hwsauth v0.5.2 h1:K4McXMEHtI5o4fAL3AZrmaMkwORNqSTV3MM6BExNKag= git.haelnorr.com/h/golib/hwsauth v0.5.2 h1:K4McXMEHtI5o4fAL3AZrmaMkwORNqSTV3MM6BExNKag=
git.haelnorr.com/h/golib/hwsauth v0.5.2/go.mod h1:NOonrVU/lX8lzuV77eDEiTwBjn7RrzYVcSdXUJWeHmQ= git.haelnorr.com/h/golib/hwsauth v0.5.2/go.mod h1:NOonrVU/lX8lzuV77eDEiTwBjn7RrzYVcSdXUJWeHmQ=
git.haelnorr.com/h/golib/jwt v0.10.1 h1:1Adxt9H3Y4fWFvFjWpvg/vSFhbgCMDMxgiE3m7KvDMI= git.haelnorr.com/h/golib/jwt v0.10.1 h1:1Adxt9H3Y4fWFvFjWpvg/vSFhbgCMDMxgiE3m7KvDMI=

View File

@@ -84,6 +84,7 @@ func Register(
user, err := registerUser(ctx, tx, username, details) user, err := registerUser(ctx, tx, username, details)
if err != nil { if err != nil {
throwInternalServiceError(server, w, r, "Registration failed", err) throwInternalServiceError(server, w, r, "Registration failed", err)
return
} }
tx.Commit() tx.Commit()
if user == nil { if user == nil {
@@ -92,6 +93,7 @@ func Register(
err = auth.Login(w, r, user, true) err = auth.Login(w, r, user, true)
if err != nil { if err != nil {
throwInternalServiceError(server, w, r, "Login failed", err) throwInternalServiceError(server, w, r, "Login failed", err)
return
} }
pageFrom := cookies.CheckPageFrom(w, r) pageFrom := cookies.CheckPageFrom(w, r)
w.Header().Set("HX-Redirect", pageFrom) w.Header().Set("HX-Redirect", pageFrom)

View File

@@ -6,7 +6,7 @@ templ RegisterForm(username string) {
hx-swap="none" hx-swap="none"
x-data={ templ.JSFuncCall("registerFormData").CallInline } x-data={ templ.JSFuncCall("registerFormData").CallInline }
@submit="handleSubmit()" @submit="handleSubmit()"
@htmx:after-request="if(submitTimeout) clearTimeout(submitTimeout); if(!$event.detail.successful) { isSubmitting=false; buttontext='Register'; if($event.detail.xhr.status === 409) { errorMessage='Username is already taken'; isUnique=false; } else { errorMessage='An error occurred. Please try again.'; } }" @htmx:after-request="if(submitTimeout) clearTimeout(submitTimeout); const redirect = $event.detail.xhr.getResponseHeader('HX-Redirect'); if(redirect) return; if(!$event.detail.successful) { isSubmitting=false; buttontext='Register'; if($event.detail.xhr.status === 409) { errorMessage='Username is already taken'; isUnique=false; } else { errorMessage='An error occurred. Please try again.'; } }"
> >
<script> <script>
function registerFormData() { function registerFormData() {
@@ -53,7 +53,7 @@ templ RegisterForm(username string) {
'py-3 px-4 block w-full rounded-lg text-sm bg-base disabled:opacity-50 disabled:pointer-events-none border-2 outline-none': true, 'py-3 px-4 block w-full rounded-lg text-sm bg-base disabled:opacity-50 disabled:pointer-events-none border-2 outline-none': true,
'border-overlay0 focus:border-blue': !isUnique && !errorMessage, 'border-overlay0 focus:border-blue': !isUnique && !errorMessage,
'border-green focus:border-green': isUnique && !isChecking && !errorMessage, 'border-green focus:border-green': isUnique && !isChecking && !errorMessage,
'border-red focus:border-red': errorMessage && !isChecking 'border-red focus:border-red': errorMessage && !isChecking && !isSubmitting
}" }"
required required
aria-describedby="username-error" aria-describedby="username-error"
@@ -69,7 +69,7 @@ templ RegisterForm(username string) {
<p <p
class="text-center text-xs text-red mt-2" class="text-center text-xs text-red mt-2"
id="username-error" id="username-error"
x-show="errorMessage" x-show="errorMessage && !isSubmitting"
x-cloak x-cloak
x-text="errorMessage" x-text="errorMessage"
></p> ></p>