Skip to content

Simplify login recipe: drop mountPath threading now that livetemplate supports relative self-redirects (#434) #45

Description

@adnaan

Context

livetemplate#434 is fixed (PR livetemplate#443, merged): ctx.Redirect now accepts relative references, so a recipe mounted behind http.StripPrefix can redirect back to its own mount via ctx.Redirect("", http.StatusSeeOther) — the browser resolves the relative Location against the full, un-stripped URL.

This makes the mountPath workaround in docs#34 unnecessary.

What to remove

The login recipe currently threads a mount path through the handler constructor purely so it can build an absolute redirect target:

  • examples/login/handler.gofunc Handler(mountPath string, opts ...livetemplate.Option) http.Handler → drop the mountPath parameter.
  • examples/login/controller.go — the mountPath string field on AuthController and the two ctx.Redirect(c.mountPath, http.StatusSeeOther) call sites (Login/Logout) → replace with ctx.Redirect("", http.StatusSeeOther).
  • examples/login/cmd/main.go — the call site passing mountPath into loginrecipe.Handler(mountPath, opts...) → drop the argument (keep the http.StripPrefix mount as-is).

Constraints / acceptance

  • Mount with a trailing slash. The empty-string "reload self" form resolves to ./ (current directory), so it relies on the canonical trailing-slash mount http.StripPrefix("/apps/login/", …) — which the recipe already uses. (See the livetemplate Redirect godoc / docs/references/authentication.md note.)
  • Requires a livetemplate dependency bump to the release that includes #443 (next tag after the current one).
  • e2e/login TestLogin_E2E_SubpathMount must still pass: successful login lands at <serverURL>/apps/login/ (not the domain root), and logout returns there too. This is the browser-side validation that the relative redirect resolves correctly.

Ref: livetemplate#434, livetemplate#443, docs#34.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions