{"slug": "give-the-agent-the-existing-session-helper-dont-invent-a-new-fetch-to-me-in-the", "title": "Give the agent the existing session helper, don’t invent a new fetch to /me in the page", "summary": "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.", "body_md": "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, loading, 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.\n\nI'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.\n\nAuth 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.\"\n\nThis is narrower than adding a second auth library. The session wrapper already exists, and the page bypasses it.\n\n`/me`, decode a JWT, or read the token from storage\nIf 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.\n\n```\nUse the existing session helper (getSession, useAuth, or useSession) for the current user.\nDo not fetch /me, decode a JWT, or read the token from storage in this page.\nIf you need a field the helper does not expose, add it to the helper; do not invent a second hook.\nKeep the loading and signed-out paths the helper already provides.\n```\n\nPaste 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.\n\n**Reject**\n\n**Accept**", "url": "https://wpnews.pro/news/give-the-agent-the-existing-session-helper-dont-invent-a-new-fetch-to-me-in-the", "canonical_source": "https://dev.to/sherotree/give-the-agent-the-existing-session-helper-dont-invent-a-new-fetch-to-me-in-the-page-1ci8", "published_at": "2026-11-27 13:37:02+00:00", "updated_at": "2026-11-27 13:46:59.073910+00:00", "lang": "en", "topics": ["ai-agents", "ai-tools", "developer-tools"], "entities": [], "also_reported_by": [], "takeaway": "Instruct coding agents to use the repo's existing session helper and reject diffs that add fetch('/api/me'), JWT decoding, localStorage token reads, or a second useCurrentUser hook.", "recommendation": {"advice": "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.", "playbook": "coding-agents", "playbook_url": "https://wpnews.pro/playbooks/coding-agents"}, "alternates": {"html": "https://wpnews.pro/news/give-the-agent-the-existing-session-helper-dont-invent-a-new-fetch-to-me-in-the", "markdown": "https://wpnews.pro/news/give-the-agent-the-existing-session-helper-dont-invent-a-new-fetch-to-me-in-the.md", "text": "https://wpnews.pro/news/give-the-agent-the-existing-session-helper-dont-invent-a-new-fetch-to-me-in-the.txt", "jsonld": "https://wpnews.pro/news/give-the-agent-the-existing-session-helper-dont-invent-a-new-fetch-to-me-in-the.jsonld"}}