Add auth middleware: Free AI Prompt | SheCodes

Free AI prompt · The Code Book

Add auth middleware

A ready-to-use prompt from the chapter Protected Routes & Roles. Paste it into Claude, ChatGPT, Lovable, Bolt or any AI coding tool.

The prompt

“Make the /dashboard and /settings pages only visible to signed-in visitors (using Supabase for login). If someone who is not signed in tries to open one of those pages, send them to the /login page, then bring them right back to where they were going as soon as they sign in. Leave the homepage, /about, and /pricing open to everyone.”

How to use it

  1. Copy the prompt and paste it into your AI coding tool.
  2. Check the result in the preview, then ask for changes one at a time: "make the buttons bigger", "use my brand colours".
  3. Read the chapter to understand why it works and what to do next.

More prompts like this

All prompts

Build an admin area

“Build a basic admin area for my app. Add a 'role' field to each user (everyone starts as a regular user, I'll mark myself as admin). If someone who isn't an admin tries to open any /admin page, send them away. Create /admin (dashboard with stats), /admin/users (a table of everyone with the ability to change their role), and /admin/posts (a list of all posts with delete buttons). Make sure the protection happens on the server so nobody can sneak in by editing their browser, not just by hiding things in the interface.”

Group-based permissions

“In my project management app, users belong to teams. Make sure each user only ever sees projects that belong to their team. Enforce this in the database itself, not just by hiding things in the interface, so there's no way to sneak around it.”

Show a proper 403 page

“When a logged-in user tries to access a page they don't have permission for, show a friendly 403 Forbidden page (not a 404 or a redirect to login). The page should say "You don't have access to this page" and have a button to go back home.”

Set up a frontend project

“Set up a new Next.js project with TypeScript, Tailwind CSS, and App Router. Create a clean homepage with a [header/hero/features] layout.”

Add multi-page navigation

“Convert my single-page app into multiple pages with proper navigation. Add routes for [home, about, dashboard, settings].”