Course Overview
Locked video preview

Watch for free

Create a free account to watch this video.

Authentication and authorization

Middleware introduction

Here is a summary of the video transcript:

  • Middleware for Route Protection
    Middleware is introduced as a maintainable way to protect specific routes instead of duplicating logic in controllers. It enables composability by allowing multiple middleware functions to be chained together.

  • Authentication Middleware
    An authentication cookie containing user ID and authentication status is checked on each protected request. If the user is not authenticated, they are redirected to the login page. Since the cookie is encrypted and authenticated, its contents can be trusted.

  • Rate Limiting Login Attempts
    To prevent brute-force attacks, login attempts are limited based on IP address. After a defined number of failed attempts, a cooldown period (e.g., 10–15 minutes) is enforced.

  • Storage Strategy for Rate Limiting
    In-memory storage is used to track login attempts, which is sufficient for a small personal application. Alternatives like databases or Redis can be implemented for more robust or scalable solutions.

  • Protection Against Denial of Service
    IP-based rate limiting prevents attackers from repeatedly attempting logins to lock out legitimate users. The attacker can only block their own IP, reducing the risk of service disruption.

  • Securing Admin Pages
    By combining authentication and rate-limiting middleware, all admin routes can be securely restricted to authorized users only.