Skip to content

How to test a route handler wrapped by auth() #13101

Open
@pacoorozco

Description

@pacoorozco

What is the improvement or update you wish to see?

The documentation doesn't explain how to test a route handler protected using the auth() handler as it is suggested.

Is there any context that might help us understand?

I've implemented a test site, see the repo, to prove it.

The /api/protected route (here) is using the auth() handler and as it's seen in the test (here), needs to somehow create a request that auth() could handle.

The usual test, see it here doesn't work. auth() is neither accepting a NextRequest nor responding a NextReponse.

The documentation should add an example of how it can be done.

Does the docs page already exist? Please link to it.

https://authjs.dev/getting-started/session-management/protecting#api-routes

Metadata

Metadata

Assignees

No one assigned

    Labels

    triageUnseen or unconfirmed by a maintainer yet. Provide extra information in the meantime.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions