How to design authentication, organizations, roles, permissions, and protected routes for a serious Next.js SaaS product.
Authentication gets users into the app. Authorization decides what they can do once they are there. In SaaS products, the second part is where many starters are too thin.
This guide covers the practical model: platform roles, organization roles, protected routes, admin access, and future enterprise needs.
The user record should contain only user-level identity:
Avoid storing organization-specific permissions directly on the user. A user can be an owner in one organization and a viewer in another.
Platform roles are global. Most apps only need:
user.admin.The admin role controls platform screens such as /admin/users, /admin/subscriptions, and /admin/feature-flags.
Do not use platform admin for customer workspace permissions.
Organization roles should answer what a user can do inside one workspace:
owner: billing, members, settings, deletion.admin: most management actions except ownership transfer.member: normal product usage.viewer: read-only access.This gives you enough granularity without creating a complex permission system too early.
Screenshot placeholder: team members table with owner, admin, member, and viewer roles.
Route protection should happen in more than one place:
The UI can hide buttons, but the server must enforce permissions.
Sign-in, sign-up, dashboard, and admin pages should not be indexed. They are not acquisition pages, and search engines do not need them.
Use:
robots metadata with index: false.robots.txt disallow rules for protected paths.This keeps SEO focus on marketing, docs, blog, pricing, and comparison pages.
Enterprise customers often ask for:
You do not need to ship every enterprise feature on day one. You do need a data model that can add them without rewriting auth and teams.
Impersonation is powerful for support, but it is sensitive.
Rules:
Write tests for:
Auth regressions are high-risk because they often expose data, not just break UI.
For a production SaaS starter, the baseline is:
That is enough to support a real product without turning the first version into an enterprise IAM project.