Resources

100 Authentication & Authorization resources for developers

This guide provides a technical roadmap for implementing authentication and authorization in modern full-stack applications. It covers provider selection, multi-tenant architecture, and security hardening patterns for developers building SaaS and enterprise-grade systems.

Auth Provider Selection and Implementation

  1. 1

    Clerk User Management

    beginnerhigh

    Use Clerk for rapid Next.js integration. It provides pre-built <SignIn /> components and a middleware-based session check that handles multi-session management out of the box.

  2. 2

    Auth.js (formerly NextAuth.js)

    intermediatehigh

    Implement for projects requiring open-source flexibility. Use the 'Database Session' strategy with the Prisma Adapter to maintain full control over user data in your own PostgreSQL instance.

  3. 3

    Lucia Auth

    intermediatestandard

    A database-agnostic library that handles session management without a heavy framework. Best for developers who want to manage their own database schemas while avoiding the complexities of low-level crypto.

  4. 4

    Supabase Auth with RLS

    intermediatehigh

    Leverage Supabase's built-in GoTrue server. Use PostgreSQL Row Level Security (RLS) to automatically filter data based on the `auth.uid()` of the requesting user.

  5. 5

    WorkOS for Enterprise SSO

    advancedhigh

    Integrate WorkOS when moving upmarket. It abstracts complex SAML and SCIM integrations into a single API, allowing connection to providers like Okta and Azure AD.

  6. 6

    Firebase Auth

    beginnerstandard

    Utilize for high-scale mobile and web apps. Use the Admin SDK on the backend to verify ID tokens and manage custom user claims for basic role-based access.

  7. 7

    Ory Kratos

    advancedmedium

    Deploy Kratos for a self-hosted, cloud-native identity server. It separates identity management from the UI, requiring you to build your own login/registration flows via API.

  8. 8

    Keycloak for On-Premise

    advancedmedium

    A robust Java-based solution for enterprise environments. Supports OIDC, SAML, and Social Login with extensive management consoles for complex LDAP integrations.

  9. 9

    Passport.js for Express

    intermediatestandard

    The legacy standard for Node.js. Use specific strategies like `passport-jwt` or `passport-google-oauth20` to modularize authentication logic in monolithic architectures.

  10. 10

    Zitadel for Multi-Tenancy

    intermediatemedium

    An open-source identity management system built specifically for multi-tenancy. Use its 'Projects' and 'Roles' features to manage access across different customer organizations.

Authorization and Multi-Tenant Architecture

  1. 1

    CASL for Isomorphic Permissions

    intermediatehigh

    Define permissions in a central `ability.ts` file using CASL. This allows you to use the same logic for UI toggles and backend API enforcement.

  2. 2

    Permit.io for Policy-as-Code

    advancedhigh

    Externalize authorization logic using Permit.io. It provides a UI for non-developers to manage roles while syncing policies to your local OPA (Open Policy Agent) instance.

  3. 3

    Cerbos for Decoupled Authz

    advancedmedium

    Run Cerbos as a sidecar or service. Define stateless policies in YAML to handle complex context-aware permissions without bloating your application code.

  4. 4

    Stripe-Based Gatekeeping

    beginnerhigh

    Sync Stripe subscription status to your user profiles. Implement middleware that checks the `subscription_status` field before allowing access to premium features or API endpoints.

  5. 5

    Hierarchical RBAC in Prisma

    intermediatemedium

    Model roles using an Enum and a join table for permissions. Use Prisma's `$use` middleware to automatically inject tenant IDs into every query for data isolation.

  6. 6

    Oso for Relationship-Based Access

    advancedmedium

    Use Oso's Polar language to define 'ReBAC' (Relationship-Based Access Control). Ideal for 'Folder > Document' style permissions where access is inherited.

  7. 7

    Clerk Organizations API

    beginnerhigh

    Use the Organizations feature to handle B2B tenant switching. Developers can use the `useOrganization` hook to fetch context-specific data without manual filtering.

  8. 8

    Auth.js Session Callbacks

    intermediatestandard

    Customize the `session` and `jwt` callbacks in Auth.js config to include the `tenantId` or `role` in the client-side session object for immediate UI updates.

  9. 9

    PostgreSQL Schema Isolation

    advancedmedium

    For high-compliance apps, use separate DB schemas per tenant. Implement a connection pooler that selects the schema based on the user's authenticated `org_id`.

  10. 10

    ABAC with User Metadata

    intermediatestandard

    Implement Attribute-Based Access Control by checking user metadata (e.g., department, location) against resource attributes during the request lifecycle.

Security Hardening and API Protection

  1. 1

    Refresh Token Rotation

    advancedhigh

    Implement rotation logic where every time a new access token is requested, the old refresh token is invalidated. This mitigates the risk of stolen long-lived tokens.

  2. 2

    PKCE for OAuth2 Flows

    intermediatehigh

    Enforce Proof Key for Code Exchange (PKCE) for all OAuth flows, including server-side, to prevent authorization code injection attacks.

  3. 3

    Upstash Rate Limiting

    beginnerhigh

    Protect auth endpoints (login, forgot password) using Upstash Redis and `@upstash/ratelimit` to prevent brute-force attacks in serverless environments.

  4. 4

    HTTP-Only Secure Cookies

    beginnerhigh

    Store session IDs or JWTs in cookies with `HttpOnly`, `Secure`, and `SameSite=Lax` flags to prevent XSS-based token theft.

  5. 5

    WebAuthn / Passkeys

    advancedmedium

    Integrate SimpleWebAuthn to allow users to authenticate using biometric hardware, significantly reducing reliance on vulnerable passwords.

  6. 6

    Iron Session for Stateless Auth

    intermediatestandard

    Use `iron-session` for encrypted, stateless, and signed cookies. It provides a session utility that works across Next.js API routes and Server Components.

  7. 7

    JWT Claims Validation

    intermediatestandard

    Always validate the `iss` (issuer), `aud` (audience), and `exp` (expiration) claims using a library like `jose` when receiving tokens from external providers.

  8. 8

    Helmet.js Security Headers

    beginnermedium

    Apply Helmet.js to your Express or Fastify app to set headers like `Content-Security-Policy` and `X-Frame-Options` to prevent clickjacking and injection.

  9. 9

    TOTP 2FA with Otplib

    intermediatemedium

    Add multi-factor authentication using `otplib` to generate and verify TOTP codes. Store the encrypted secret in your database, never in plain text.

  10. 10

    AI Endpoint Rate Limiting

    intermediatehigh

    Use per-user usage tracking in your auth middleware to limit OpenAI/Anthropic API calls, preventing a single authenticated user from draining your credits.