cd /news/ai-agents/how-to-write-a-prd-for-auth-roles-se… Β· home β€Ί topics β€Ί ai-agents β€Ί article
[ARTICLE Β· art-179948] src=dev.to β†— pub= topic=ai-agents verified=true sentiment=Β· neutral

How to write a PRD for auth: roles, sessions, and permissions your AI agent won't guess

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.

recommendation

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.

more in playbook: Working with AI coding agents
by read9 min views8 publishedDec 2, 2026

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.

Auth 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.

"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.

For TaskPulse, the roles get their own section in PRODUCT_REQUIREMENTS.md, as a matrix:

## FEAT-022 β€” Roles & Permissions

Roles: Owner, Admin, Member, Viewer.

| Action                | Owner | Admin | Member | Viewer |
|-----------------------|-------|-------|--------|--------|
| Create / edit sprints | Yes   | Yes   | Yes    | No     |
| Delete a sprint       | Yes   | Yes   | No     | No     |
| Invite a member       | Yes   | Yes   | No     | No     |
| Change a member's role| Yes   | No    | No     | No     |
| Remove a member       | Yes   | No    | No     | No     |
| View sprint board     | Yes   | Yes   | Yes    | Yes    |
| Export sprint data    | Yes   | Yes   | No     | No     |
| Delete the workspace  | Yes   | No    | No     | No     |

Two 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.

The acceptance criteria are checkable, not aspirational:

- GIVEN a Member, WHEN they call DELETE /api/v1/sprints/[id],
  THEN the API returns 403 and the sprint still exists.
- GIVEN an Admin, WHEN they try to change a Member's role,
  THEN the API returns 403 β€” only the Owner can do this.
- GIVEN a Viewer, WHEN they open the sprint board,
  THEN they see the board but no edit, delete, or export buttons.

Rule: if a permission is not in the matrix, the agent will assume it exists. Write the "No" cells as carefully as the "Yes" cells.

A 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?

For TaskPulse, the session rules are written out:

## FEAT-023 β€” Sessions

- **Sign-in**: Google OAuth only. No passwords are stored.
- **Session length**: 30 days of inactivity, then the user must
  sign in again. Activity resets the clock.
- **Two devices**: a user may be signed in on many devices;
  signing out of one device does not sign out the others.
- **Expiry mid-work**: if a session expires while the user is
  editing, the draft is kept locally and the user is asked to
  sign in again β€” the work is never lost to a redirect.
- **Sign-out everywhere**: the Owner can revoke every session
  of a removed member immediately, from the member settings page.

The 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.

The 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.

This 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.

TaskPulse stores the role in the membership table, and the RLS policies enforce the matrix:

-- Roles live on the membership row, not on the user
CREATE TABLE public.workspace_members (
  id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
  workspace_id UUID NOT NULL REFERENCES public.workspaces(id) ON DELETE CASCADE,
  user_id UUID NOT NULL REFERENCES auth.users(id) ON DELETE CASCADE,
  role TEXT NOT NULL CHECK (role IN ('owner', 'admin', 'member', 'viewer')),
  created_at TIMESTAMPTZ DEFAULT now(),
  UNIQUE (workspace_id, user_id)
);

ALTER TABLE public.workspace_members ENABLE ROW LEVEL SECURITY;

-- A member can see who else is in their own workspace
CREATE POLICY "Members see their workspace roster"
  ON public.workspace_members FOR SELECT USING (
    workspace_id IN (
      SELECT workspace_id FROM public.workspace_members
      WHERE user_id = auth.uid()
    )
  );

-- Only the Owner can change a role β€” the matrix, enforced by the database
CREATE POLICY "Only owner changes roles"
  ON public.workspace_members FOR UPDATE USING (
    EXISTS (
      SELECT 1 FROM public.workspace_members m
      WHERE m.workspace_id = workspace_members.workspace_id
        AND m.user_id = auth.uid()
        AND m.role = 'owner'
    )
  );

The 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.

The API contract carries the rest, in TECHNICAL_ARCHITECTURE.md:

// POST /api/v1/workspaces/[id]/members/invite
export const InviteMemberSchema = z.object({
  workspaceId: z.string().uuid(),
  email: z.string().email(),
  // The role must come from the matrix β€” no free-text roles
  role: z.enum(['admin', 'member', 'viewer']),
});

// PATCH /api/v1/workspaces/[id]/members/[memberId]/role
export const ChangeRoleSchema = z.object({
  workspaceId: z.string().uuid(),
  memberId: z.string().uuid(),
  role: z.enum(['owner', 'admin', 'member', 'viewer']),
  // Ownership transfer is a separate, deliberate action
  // and requires the caller's current role to be 'owner'.
});

Note 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.

Auth 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.

UI_UX_SPECIFICATION.md carries four auth states for TaskPulse:

## Auth states

- **Signed out**: the login screen, with Google sign-in only
  and a one-line explanation of what the product does.
- **Session expired**: "Your session expired. Sign in again to
  continue." The user's unsaved draft is preserved and
  restored after sign-in.
- **Insufficient permission**: "You don't have permission to do
  that." The screen names the action and the role that can
  perform it β€” "Only the workspace Owner can change roles" β€”
  so the user knows who to ask instead of filing a bug report.
- **Removed from workspace**: "You've been removed from this
  workspace." No retry button, no dead links β€” a link back to
  the user's own workspaces.

The "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.

Auth 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:

Phase 2 β€” FEAT-022/023 Auth & Roles
1. Implement the membership table and RLS policies exactly as
   specified in TECHNICAL_ARCHITECTURE.md Β§1.
2. Build the sign-in, session-expiry, and four auth states from
   UI_UX_SPECIFICATION.md.
3. Run the permission matrix as a test: for every row of the
   matrix, sign in as that role and attempt the action.
   Every "No" cell must return 403; every "Yes" cell must succeed.
4. Test the removal path: remove a member, then confirm their
   open session is revoked immediately β€” not after expiry.
5. Test the transfer path: transfer ownership, then confirm the
   old Owner can no longer change roles and the new Owner can.
6. If any matrix cell behaves differently from the spec, stop
   and report which cell β€” do not widen a permission to make
   a test pass.

That 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.

This 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.

A 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.

If 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 β€” and the free template behind the format is in the ai-prd-template repo.

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.

── more in #ai-agents 4 stories Β· sorted by recency
── more on @taskpulse 3 stories trending now
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/how-to-write-a-prd-f…] indexed:0 read:9min 2026-12-02 Β· β€”