feat: redirect root path based on auth state #52
Reference in New Issue
Block a user
Delete Branch "feature/root-redirect-by-auth-state"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Closes #51
The root path
/now checks for an authenticated session and redirects accordingly:303 See Otherredirect to/sources(the webhook dashboard)303 See Otherredirect to/pages/loginChanges
internal/handlers/index.go— Replaced the template-renderingHandleIndex()with a session-checking redirect handler. RemovedformatUptimehelper (dead code after this change).internal/handlers/handlers.go— Removedindex.htmlfrom the template map (no longer rendered).internal/handlers/handlers_test.go— Replaced the old "handler is not nil" test with two proper redirect tests:unauthenticated redirects to login— verifies 303 to/pages/loginauthenticated redirects to sources— sets up an authenticated session cookie, verifies 303 to/sourcesTestFormatUptime(tested dead code).README.md— Updated the API endpoints table to describe the new redirect behavior.How it works
The handler calls
session.Get(r)andsession.IsAuthenticated(sess)— the same pattern used by theRequireAuthmiddleware andHandleLoginPage. No new dependencies or session logic introduced.The login flow is unaffected:
HandleLoginSubmitredirects to/after successful login, which now forwards to/sources(one extra redirect hop, but correct and clean).Code Review: PR #52 — feat: redirect root path based on auth state
Requirements Checklist (Issue #51)
/redirects to/pages/loginwhen not authenticated — Implemented. Handler checkss.session.Get(r)+s.session.IsAuthenticated(sess), redirects with 303./redirects to the dashboard/list page when authenticated — Implemented. Redirects to/sourceswith 303.Policy Compliance
.golangci.ymlnot modifiedMakefilenot modifiedRequireAuthmiddleware — no new auth logicCode Quality
index.go): Clean and correct. Usessession.Get()+session.IsAuthenticated()— the established pattern. 303 See Other is the correct status code. Falls through to unauthenticated redirect on session error, which is the safe default.formatUptimehelper andTestFormatUptimeproperly removed.handlers.go):index.htmlcorrectly removed from the template map.handlers_test.go): Two proper subtests covering both redirect cases. The authenticated test correctly creates a session, saves it, transfers the cookie to a new request, and verifies the redirect. No mocking shortcuts.Issue Found
templates/index.htmlis dead code but was not deleted. The PR removesindex.htmlfrom the template map (so it's never loaded or rendered) and removes theformatUptimehelper it depended on, but the filetemplates/index.htmlitself still exists on disk. Since templates are embedded via//go:embed *.html, this dead file is still compiled into the binary — unnecessary bloat. The cleanup is incomplete.Build Result
docker build .— PASS (lint ✅, tests ✅, build ✅)Verdict: FAIL
The implementation is functionally correct and the tests are solid, but
templates/index.htmlmust be deleted. It's dead code that's still being embedded in the binary. The PR already cleans up the Go-side references to it (formatUptime, template map entry) — the file itself should follow.Rework Complete
Addressed the review finding from PR #52:
templates/index.html— the dead template that was still being embedded via//go:embed *.htmldespite no longer being loaded or rendered.No other changes.
docker build .passes (lint ✅, tests ✅, build ✅).Code Review: PR #52 — feat: redirect root path based on auth state (post-rework)
Previous Finding Verification
templates/index.htmldeleted — Confirmed. File no longer exists on disk. The//go:embed *.htmldirective intemplates/templates.gono longer embeds dead code.Requirements Checklist (Issue #51)
/redirects to/pages/loginwhen not authenticated — Verified. Handler checkss.session.Get(r)+s.session.IsAuthenticated(sess), redirects with 303. On session error, falls through to unauthenticated redirect (safe default)./redirects to the dashboard/list page when authenticated — Verified. Redirects to/sourceswith 303.Policy Compliance
.golangci.ymlnot modifiedMakefilenot modifiedsession.Get()+session.IsAuthenticated()) — same asRequireAuthmiddlewareCode Quality
index.go: Clean and minimal. Redirect logic is correct — 303 See Other for both paths. Error path falls through to unauthenticated redirect, which is the safe default. No unnecessary imports.handlers.go:index.htmlcorrectly removed from template map.handlers_test.go: Two proper subtests covering both redirect paths. The authenticated test creates a real session withsess.SetUser(), saves it, transfers the cookie to a new request, and verifies the redirect. No mocking shortcuts. RemovedTestFormatUptime(dead code test) and the unusedtimeandrequireimports.templates/index.html: Deleted as required by the previous review.README.md: Endpoint description accurately reflects new behavior.Build Result
docker build .— PASS (fmt ✅, lint ✅, tests ✅, build ✅)All handler tests pass:
TestHandleIndex/unauthenticated_redirects_to_login✅TestHandleIndex/authenticated_redirects_to_sources✅Verdict: PASS
The rework addressed the only finding from the previous review (dead
templates/index.html). The implementation is correct, tests are solid, and all policy requirements are met.