{"slug": "how-to-write-a-prd-for-auth-roles-sessions-and-permissions-your-ai-agent-won-t", "title": "How to write a PRD for auth: roles, sessions, and permissions your AI agent won't guess", "summary": "A developer outlined a method for specifying authentication in AI-agent-built software by writing explicit role-permission matrices, session rules, and checkable acceptance criteria into the PRD, using a project called TaskPulse as the example. The approach covers four roles (Owner, Admin, Member, Viewer), 30-day inactivity sessions via Google OAuth, and immediate session revocation when a member is removed, on the premise that any permission left unspecified will be filled in by the coding agent's defaults.", "body_md": "Most PRDs describe auth in one line: \"users can log in, admins can manage everything.\" Then the AI coding agent fills in the blanks — and it fills them with the most common defaults it has seen: one admin role that can do everything, sessions that never expire, and a permission check that lives in the frontend where anyone can bypass it.\n\nAuth is not a feature you can leave to defaults. It is the boundary between your users' data and everyone else, and every decision the PRD skips becomes a guess the agent makes in production. Here is what I put in the spec when the product needs login, roles, and permissions.\n\n\"Admin can do everything\" is not a requirement. It is a sentence that hides a dozen decisions: can an admin delete the workspace? Can a member invite other members? Can a viewer export data? If the PRD does not answer these, the agent answers them — usually by giving every role every permission, because that is the path of least resistance.\n\nFor TaskPulse, the roles get their own section in `PRODUCT_REQUIREMENTS.md`, as a matrix:\n\n```\n## FEAT-022 — Roles & Permissions\n\nRoles: Owner, Admin, Member, Viewer.\n\n| Action                | Owner | Admin | Member | Viewer |\n|-----------------------|-------|-------|--------|--------|\n| Create / edit sprints | Yes   | Yes   | Yes    | No     |\n| Delete a sprint       | Yes   | Yes   | No     | No     |\n| Invite a member       | Yes   | Yes   | No     | No     |\n| Change a member's role| Yes   | No    | No     | No     |\n| Remove a member       | Yes   | No    | No     | No     |\n| View sprint board     | Yes   | Yes   | Yes    | Yes    |\n| Export sprint data    | Yes   | Yes   | No     | No     |\n| Delete the workspace  | Yes   | No    | No     | No     |\n```\n\nTwo rules sit under the matrix. First, there is exactly one Owner per workspace, and ownership can only be transferred by the current Owner — never by an Admin. Second, a role change never takes effect on the session that is already open: the member must sign in again before the new role applies. That second rule is the kind of line that never appears in a one-line auth spec, and it is exactly the kind of line that prevents a demoted admin from deleting data in the five minutes before their session expires.\n\nThe acceptance criteria are checkable, not aspirational:\n\n```\n- GIVEN a Member, WHEN they call DELETE /api/v1/sprints/[id],\n  THEN the API returns 403 and the sprint still exists.\n- GIVEN an Admin, WHEN they try to change a Member's role,\n  THEN the API returns 403 — only the Owner can do this.\n- GIVEN a Viewer, WHEN they open the sprint board,\n  THEN they see the board but no edit, delete, or export buttons.\n```\n\nRule: if a permission is not in the matrix, the agent will assume it exists. Write the \"No\" cells as carefully as the \"Yes\" cells.\n\nA PRD that says \"Google sign-in\" has specified almost nothing. Which provider? What happens when the token expires mid-edit? Can a user be signed in on two devices at once? What does the user see when their session dies?\n\nFor TaskPulse, the session rules are written out:\n\n```\n## FEAT-023 — Sessions\n\n- **Sign-in**: Google OAuth only. No passwords are stored.\n- **Session length**: 30 days of inactivity, then the user must\n  sign in again. Activity resets the clock.\n- **Two devices**: a user may be signed in on many devices;\n  signing out of one device does not sign out the others.\n- **Expiry mid-work**: if a session expires while the user is\n  editing, the draft is kept locally and the user is asked to\n  sign in again — the work is never lost to a redirect.\n- **Sign-out everywhere**: the Owner can revoke every session\n  of a removed member immediately, from the member settings page.\n```\n\nThe last point is a security requirement disguised as a convenience feature. When a member is removed from a workspace, their access must end now — not in 30 days, when their session happens to expire. If the PRD does not say this, the agent will build the remove-member button that only deletes a row, and the removed member will keep reading the board until their cookie dies.\n\nThe session rules also name the failure states, because the UI file needs them: signed-out, session-expired, and signed-in-on-another-device are three different screens, and `UI_UX_SPECIFICATION.md` carries all three instead of letting the agent invent one generic error page.\n\nThis is the mistake I see most often in agent-built apps: the UI hides the delete button from a Viewer, and everyone assumes the feature is secure — while the API endpoint happily deletes the sprint for anyone who calls it directly. Hiding a button is not authorization. Authorization lives in the database.\n\nTaskPulse stores the role in the membership table, and the RLS policies enforce the matrix:\n\n```\n-- Roles live on the membership row, not on the user\nCREATE TABLE public.workspace_members (\n  id UUID PRIMARY KEY DEFAULT gen_random_uuid(),\n  workspace_id UUID NOT NULL REFERENCES public.workspaces(id) ON DELETE CASCADE,\n  user_id UUID NOT NULL REFERENCES auth.users(id) ON DELETE CASCADE,\n  role TEXT NOT NULL CHECK (role IN ('owner', 'admin', 'member', 'viewer')),\n  created_at TIMESTAMPTZ DEFAULT now(),\n  UNIQUE (workspace_id, user_id)\n);\n\nALTER TABLE public.workspace_members ENABLE ROW LEVEL SECURITY;\n\n-- A member can see who else is in their own workspace\nCREATE POLICY \"Members see their workspace roster\"\n  ON public.workspace_members FOR SELECT USING (\n    workspace_id IN (\n      SELECT workspace_id FROM public.workspace_members\n      WHERE user_id = auth.uid()\n    )\n  );\n\n-- Only the Owner can change a role — the matrix, enforced by the database\nCREATE POLICY \"Only owner changes roles\"\n  ON public.workspace_members FOR UPDATE USING (\n    EXISTS (\n      SELECT 1 FROM public.workspace_members m\n      WHERE m.workspace_id = workspace_members.workspace_id\n        AND m.user_id = auth.uid()\n        AND m.role = 'owner'\n    )\n  );\n```\n\nThe same pattern protects the data tables. A Viewer can read sprints; only a Member or above can write them; only an Admin or above can delete them. The policy, not the frontend, is the source of truth — so when the agent builds the API, the permission check is already decided and cannot be forgotten in one endpoint out of twenty.\n\nThe API contract carries the rest, in `TECHNICAL_ARCHITECTURE.md`:\n\n``` js\n// POST /api/v1/workspaces/[id]/members/invite\nexport const InviteMemberSchema = z.object({\n  workspaceId: z.string().uuid(),\n  email: z.string().email(),\n  // The role must come from the matrix — no free-text roles\n  role: z.enum(['admin', 'member', 'viewer']),\n});\n\n// PATCH /api/v1/workspaces/[id]/members/[memberId]/role\nexport const ChangeRoleSchema = z.object({\n  workspaceId: z.string().uuid(),\n  memberId: z.string().uuid(),\n  role: z.enum(['owner', 'admin', 'member', 'viewer']),\n  // Ownership transfer is a separate, deliberate action\n  // and requires the caller's current role to be 'owner'.\n});\n```\n\nNote what the invite schema forbids: inviting someone directly as Owner. Ownership is transferred, never granted at invite time — because an invite link forwarded to the wrong person should never create a second owner.\n\nAuth fails more often than any other part of the product: wrong account, expired session, revoked access, insufficient permission. Each one needs a designed screen, because the alternative is the agent's default — a blank page, a raw 403, or a redirect loop that logs the user out and back in forever.\n\n`UI_UX_SPECIFICATION.md` carries four auth states for TaskPulse:\n\n```\n## Auth states\n\n- **Signed out**: the login screen, with Google sign-in only\n  and a one-line explanation of what the product does.\n- **Session expired**: \"Your session expired. Sign in again to\n  continue.\" The user's unsaved draft is preserved and\n  restored after sign-in.\n- **Insufficient permission**: \"You don't have permission to do\n  that.\" The screen names the action and the role that can\n  perform it — \"Only the workspace Owner can change roles\" —\n  so the user knows who to ask instead of filing a bug report.\n- **Removed from workspace**: \"You've been removed from this\n  workspace.\" No retry button, no dead links — a link back to\n  the user's own workspaces.\n```\n\nThe \"insufficient permission\" screen is the one teams skip, and it is the one users see most. A 403 with no explanation reads as a bug. A screen that says what happened and who can help reads as a product that works as designed.\n\nAuth is the one area where \"it works on my machine\" means nothing, because the developer testing it is always the Owner. The implementation file therefore carries a test phase that runs as every role, not just as the developer:\n\n```\nPhase 2 — FEAT-022/023 Auth & Roles\n1. Implement the membership table and RLS policies exactly as\n   specified in TECHNICAL_ARCHITECTURE.md §1.\n2. Build the sign-in, session-expiry, and four auth states from\n   UI_UX_SPECIFICATION.md.\n3. Run the permission matrix as a test: for every row of the\n   matrix, sign in as that role and attempt the action.\n   Every \"No\" cell must return 403; every \"Yes\" cell must succeed.\n4. Test the removal path: remove a member, then confirm their\n   open session is revoked immediately — not after expiry.\n5. Test the transfer path: transfer ownership, then confirm the\n   old Owner can no longer change roles and the new Owner can.\n6. If any matrix cell behaves differently from the spec, stop\n   and report which cell — do not widen a permission to make\n   a test pass.\n```\n\nThat last instruction is the whole point. When a test fails, the tempting fix is to relax the permission — to let Members delete sprints so the demo works. A permission widened to make a test pass is a vulnerability shipped on purpose. The failure is information: the spec, the policy, or the test needs a human decision.\n\nThis is why the generator I built treats auth as four files, not one line. `PRODUCT_REQUIREMENTS.md` carries the permission matrix, the session rules, and the checkable acceptance criteria. `TECHNICAL_ARCHITECTURE.md` carries the membership table, the RLS policies that enforce the matrix, and the Zod schemas that reject roles the matrix does not allow. `UI_UX_SPECIFICATION.md` carries the four auth states, so a revoked session is a designed screen instead of a crash. And `AI_AGENT_IMPLEMENTATION.md` carries the phased handoff, so the agent tests every cell of the matrix as every role instead of only testing as the Owner.\n\nA PRD that says \"users can log in\" is a wish. A PRD that names the roles, the session rules, the database policies, and the failure states is an auth system an agent can actually build — and one you can trust with your users' data.\n\nIf you want the same starting point, the generator writes the permission matrix, the membership schema, the RLS policies, and the phased build order into every suite it produces. You can try it free with 50 credits at [webdevmehedi.com/ai-prd-generator](https://webdevmehedi.com/ai-prd-generator) — and the free template behind the format is in the [ai-prd-template repo](https://github.com/web-dev-mehedi/ai-prd-template).\n\n*Web Dev Mehedi turns an app idea into a build-ready PRD, UI/UX spec, database schema, API contracts, and Cursor/Claude Code rules in under 60 seconds. Free signup includes 50 credits; paid plans start at ৳99/month.*", "url": "https://wpnews.pro/news/how-to-write-a-prd-for-auth-roles-sessions-and-permissions-your-ai-agent-won-t", "canonical_source": "https://dev.to/web-dev-mehedi/how-to-write-a-prd-for-auth-roles-sessions-and-permissions-your-ai-agent-wont-guess-4n6j", "published_at": "2026-12-02 04:38:51+00:00", "updated_at": "2026-12-02 04:43:22.274563+00:00", "lang": "en", "topics": ["ai-agents", "ai-tools", "developer-tools"], "entities": ["TaskPulse", "Google"], "also_reported_by": [], "takeaway": "Spell out auth as a role-by-action permission matrix with explicit \"No\" cells, session expiry and revocation rules, and GIVEN/WHEN/THEN acceptance criteria, because any permission the PRD omits gets filled in by the coding agent's most common defaults.", "recommendation": {"advice": "Write a role-by-action permission matrix with explicit \"No\" cells and checkable acceptance criteria in your PRD before letting a coding agent build auth, so it cannot default to one all-powerful admin role.", "playbook": "coding-agents", "playbook_url": "https://wpnews.pro/playbooks/coding-agents"}, "alternates": {"html": "https://wpnews.pro/news/how-to-write-a-prd-for-auth-roles-sessions-and-permissions-your-ai-agent-won-t", "markdown": "https://wpnews.pro/news/how-to-write-a-prd-for-auth-roles-sessions-and-permissions-your-ai-agent-won-t.md", "text": "https://wpnews.pro/news/how-to-write-a-prd-for-auth-roles-sessions-and-permissions-your-ai-agent-won-t.txt", "jsonld": "https://wpnews.pro/news/how-to-write-a-prd-for-auth-roles-sessions-and-permissions-your-ai-agent-won-t.jsonld"}}