Skip to content

Ch 15 authentication doesn't mention that middlewares are only a first line of defense #902

@eric-burel

Description

@eric-burel

Hi,

The authentication chapter describes using NextAuth to protect routes using a middleware.

However in currently advocated best practices, middleware authentication checks have to be understood as a first line of defense. They should be completed by authorization checks at the Data Access Layer level.

The only use case where the middleware is enough, is when setting up a paywall against static content, because an authentication check at middleware level doesn't opt into dynamic rendering, contrary to a check during data fetching. Also in the same article I've described the potential footgun of authenticating in layouts: it might be worth explaining in this tutorial maybe, so this mistakes is avoided early on.

In terms of edits, I would simply suggest adding a few lines of text to explain exactly that, that you should also check authorization in the Data Access Layer and avoid checks in layouts.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions