cd /news/ai-agents/give-the-agent-the-existing-session-… · home › topics › ai-agents › article
[ARTICLE · art-177304] src=dev.to ↗ pub= topic=ai-agents verified=true sentiment=· neutral

Give the agent the existing session helper, don’t invent a new fetch to /me in the page

A developer argues that feature pages should reuse an existing session helper (getSession, useAuth, or useSession) rather than adding a one-off fetch('/api/me'), a new useCurrentUser hook, or a raw localStorage token read, treating such duplication as a consistency bug. The post recommends giving coding agents an explicit instruction to use the shared helper, pasting its exports or an existing usage, and reviewing diffs for /me, /api/auth, localStorage token reads, jwt, and new user hooks.

recommendation

When prompting or reviewing coding agents on auth-related pages, paste the existing session helper's exports and reject any diff introducing /me fetches, token reads, or duplicate user hooks.

more in playbook: Working with AI coding agents
by read2 min views5 publishedNov 27, 2026

The PR needs the current user and adds fetch('/api/me'), a new useCurrentUser hook, or a raw localStorage.getItem('token') read in the page. The repo already has a session helper (getSession, useAuth, or useSession) that the rest of the UI uses for the signed-in user, , and signed-out states. The new call looks fine in isolation and then disagrees with the header, expires the token differently, or skips the existing error path.

I've started treating a one-off /me fetch in a feature page as a consistency bug, not as a quicker read. The helper is there so every screen does not invent its own idea of "who is signed in." This article was written with the assistance of AI.

Auth tutorials start with fetch('/me') or a token in localStorage. The model can write that without finding useAuth. Your helper may live under lib/auth or a provider folder, which is easy to miss if the prompt only says "show the current user's name."

This is narrower than adding a second auth library. The session wrapper already exists, and the page bypasses it.

/me, decode a JWT, or read the token from storage If the page needs a permission the helper already exposes, use that flag. Do not re-derive "is admin" from a raw user payload in the view.

Use the existing session helper (getSession, useAuth, or useSession) for the current user.
Do not fetch /me, decode a JWT, or read the token from storage in this page.
If you need a field the helper does not expose, add it to the helper; do not invent a second hook.
Keep the  and signed-out paths the helper already provides.

Paste the helper's exports or one existing usage. In review, search the diff for /me, /api/auth, localStorage token reads, jwt, and a new useCurrentUser or getUser that is not the shared helper.

Reject

Accept

── more in #ai-agents 4 stories · sorted by recency
sponsored brought to you by zahid.host 4,200+ EU-deployed projects
reading about agents? ship yours in a single git push.

Run your AI side-project on zahid.host

EU-based hosting, git-push deploys, automatic HTTPS, no cold starts. Free tier with a custom domain — perfect for shipping the agent you just read about.

$git push zahid main
→ Live at https://your-agent.zahid.host ✓
Get free account → Pricing
from €0/mo · no card required
LIVE [news/give-the-agent-the-e…] indexed:0 read:2min 2026-11-27 · —