tag claim flow: scanned code auto-fills Add Tag field (?code=), unclaimed tag page shows 'Add this tag to my account' when logged in, login honors next= so code survives the login step

This commit is contained in:
2026-08-10 17:04:21 +10:00
parent 04fd5ac63a
commit 1fae314eb4
5 changed files with 24 additions and 7 deletions

View File

@@ -64,7 +64,11 @@ func (a *App) Register(w http.ResponseWriter, r *http.Request) {
http.Error(w, "internal error", http.StatusInternalServerError)
return
}
http.Redirect(w, r, "/account", http.StatusSeeOther)
next := r.FormValue("next")
if next == "" || !strings.HasPrefix(next, "/") || strings.HasPrefix(next, "//") {
next = "/account"
}
http.Redirect(w, r, next, http.StatusSeeOther)
}
func (a *App) LoginPage(w http.ResponseWriter, r *http.Request) {
@@ -93,7 +97,11 @@ func (a *App) Login(w http.ResponseWriter, r *http.Request) {
http.Error(w, "internal error", http.StatusInternalServerError)
return
}
http.Redirect(w, r, "/account", http.StatusSeeOther)
next := r.FormValue("next")
if next == "" || !strings.HasPrefix(next, "/") || strings.HasPrefix(next, "//") {
next = "/account"
}
http.Redirect(w, r, next, http.StatusSeeOther)
}
func (a *App) Logout(w http.ResponseWriter, r *http.Request) {

View File

@@ -13,6 +13,7 @@ import (
type publicData struct {
UpdatedAt pgtype.Timestamptz
Preview bool
Authed bool
ID int64
TagCode string
Status string
@@ -48,8 +49,10 @@ func (a *App) PublicTag(w http.ResponseWriter, r *http.Request) {
return
}
_, authed := auth.GetUserID(r)
pd := publicData{
Preview: r.URL.Query().Get("preview") == "1",
Authed: authed,
UpdatedAt: tag.UpdatedAt,
ID: tag.ID,
TagCode: tag.TagCode,

View File

@@ -18,8 +18,9 @@ import (
const maxTagsPerAccount = 20
type accountData struct {
Tags []db.Tag
AddError string
Tags []db.Tag
AddError string
AddTagCode string
}
func ownerID(uid int64) pgtype.Int8 {
@@ -33,7 +34,7 @@ func (a *App) Account(w http.ResponseWriter, r *http.Request) {
http.Error(w, "internal error", http.StatusInternalServerError)
return
}
a.render(w, r, "account", "My Tags", accountData{Tags: tags}, "")
a.render(w, r, "account", "My Tags", accountData{Tags: tags, AddTagCode: r.URL.Query().Get("code")}, "")
}
// AddTag binds a tag code to the current account (HTMX: returns account-panel).
@@ -44,6 +45,7 @@ func (a *App) AddTag(w http.ResponseWriter, r *http.Request) {
oid := ownerID(uid)
data := accountData{}
data.AddTagCode = code
if code == "" {
data.AddError = "Enter a tag code."
} else {