Skip to content

[code-simplifier] Remove redundant refreshCookieName guard in issueTokens#337

Merged
veverkap merged 2 commits into
mainfrom
code-simplifier/remove-redundant-refresh-cookie-check-91796afecc562c47
May 23, 2026
Merged

[code-simplifier] Remove redundant refreshCookieName guard in issueTokens#337
veverkap merged 2 commits into
mainfrom
code-simplifier/remove-redundant-refresh-cookie-check-91796afecc562c47

Conversation

@github-actions
Copy link
Copy Markdown
Contributor

@github-actions github-actions Bot commented May 23, 2026

Code Simplification - 2026-05-23

This PR simplifies recently modified code to improve clarity while preserving all functionality.

Files Simplified

  • handler/helpers.go - Removed a redundant if refreshCookieName != "" guard inside issueTokens

Improvement

The issueTokens function already contains an early return at the top:

if sessions != nil && refreshCookieName == "" {
    // ... returns false
}

Because of this guard, when execution reaches the SetRefreshCookie call (inside the sessions != nil branch), refreshCookieName is provably non-empty. The inner if refreshCookieName != """ check was therefore always trueand could never befalse`. Removing it makes the invariant explicit and the code easier to read.

Changes Based On

Recent changes from:

Testing

  • ✅ All handler tests pass (go test ./handler/...)
  • ✅ No functional changes — behavior is identical

Automated by Code Simplifier Agent - analyzing code from the last 24 hours

Generated by 🔧 Code Simplifier · ● 1.3M ·

Add this agentic workflows to your repo

To install this agentic workflow, run

gh aw add github/gh-aw/.github/workflows/code-simplifier.md@d48a1ded1ae2ed4d940f927d461d9a8224196718
  • expires on May 24, 2026, 6:14 PM UTC

Greptile Summary

This PR removes a dead-code guard (if refreshCookieName != "") that wrapped SetRefreshCookie inside issueTokens. Because the function already returns early whenever sessions != nil && refreshCookieName == "", any code path that reaches the sessions != nil branch is guaranteed to have a non-empty refreshCookieName, making the inner check always-true and therefore unnecessary.

  • The early-return guard at line 45 (sessions != nil && refreshCookieName == "") is the sole enforcement point, and it remains untouched.
  • All callers pass h.RefreshCookieName (validated at startup); the test at helpers_test.go:586 explicitly covers the misconfiguration path.

Confidence Score: 5/5

Safe to merge — the removed guard was provably dead code and the change is purely cosmetic with no behavioral impact.

The early-return at the top of issueTokens already covers the only case where refreshCookieName could be empty while sessions is non-nil, so the deleted inner guard could never have been false. No logic paths change, no new error conditions are introduced, and existing tests confirm the misconfiguration path is still handled correctly.

No files require special attention.

Important Files Changed

Filename Overview
handler/helpers.go Removed redundant if refreshCookieName != "" guard around SetRefreshCookie; the invariant is fully enforced by the existing early return at line 45 (sessions != nil && refreshCookieName == ""), making the inner check provably dead code.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[issueTokens called] --> B{sessions != nil\nAND\nrefreshCookieName == ?}
    B -- "sessions != nil\n&& refreshCookieName == ''" --> C[Return early\nHTTP 500 + false]
    B -- "sessions == nil\nOR refreshCookieName != ''" --> D{sessions != nil?}
    D -- No --> E[CreateToken\nSetAuthCookie\nReturn token]
    D -- Yes\nrefreshCookieName guaranteed non-empty --> F[GenerateRandomHex\nCreateSession\nCreateTokenWithSession]
    F --> G[SetRefreshCookie\n✅ called directly\nno inner guard needed]
    G --> H[SetAuthCookie\nReturn tokens]
Loading

Reviews (1): Last reviewed commit: "Merge branch 'main' into code-simplifier..." | Re-trigger Greptile

The early return at the top of issueTokens already guarantees that
refreshCookieName is non-empty when sessions is non-nil, making the
inner 'if refreshCookieName != ""' check unreachable-false. Remove
it to make the invariant clearer.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@veverkap veverkap marked this pull request as ready for review May 23, 2026 19:22
@veverkap veverkap requested review from a team and Copilot May 23, 2026 19:22
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR simplifies issueTokens in handler/helpers.go by removing a redundant refreshCookieName != "" conditional before setting the refresh cookie. The function already fails fast when sessions != nil and refreshCookieName == "", so the removed condition could never be false in the sessions != nil branch.

Changes:

  • Remove the redundant inner guard around SetRefreshCookie inside the sessions != nil flow.
  • Make the “refresh cookie name is non-empty when sessions are enabled” invariant explicit by always calling SetRefreshCookie in that branch.
Show a summary per file
File Description
handler/helpers.go Removes an unreachable conditional and always sets the refresh cookie when sessions are enabled (protected by the existing early misconfiguration guard).

Copilot's findings

Tip

Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

  • Files reviewed: 1/1 changed files
  • Comments generated: 0

@veverkap veverkap merged commit 564397d into main May 23, 2026
14 checks passed
@veverkap veverkap deleted the code-simplifier/remove-redundant-refresh-cookie-check-91796afecc562c47 branch May 23, 2026 19:50
@github-actions github-actions Bot mentioned this pull request May 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants