Skip to content

Server-side HTTP requests via getSession usually get extremely slow on Vercel #1535

@kripod

Description

@kripod

Describe the bug

Before further ado, here’s a comparison between a /api/user/{id} request which fetches /api/auth/session through the network even on the server side, versus a /api/site/{id} call, which isn’t protected via getSession. Unfortunately, there’s a quite large margin between response times.

image

Steps to reproduce
Call getSession on the server side and observe that it makes an HTTP request instead of just calling functions locally.

Expected behavior
Calls to getSession should be executed locally in a server environment. A separate getServerSession method could be added as a non-isomorphic solution without any HTTP calls.

Additional context
According to the official Next.js docs:

You should not use fetch() to call an API route in getServerSideProps. Instead, directly import the logic used inside your API route. You may need to slightly refactor your code for this approach.

Fetching from an external API is fine!

This seems to hurt performance badly.

Feedback
Documentation refers to searching through online documentation, code comments and issue history. The example project refers to next-auth-example.

  • Found the documentation helpful
  • Found documentation but was incomplete
  • Could not find relevant documentation
  • Found the example project helpful
  • Did not find the example project helpful

Thank you for maintaining this wonderful library – it really helps a lot! 🙏

Metadata

Metadata

Assignees

Labels

bugSomething isn't workinghelp-neededThe maintainer needs help due to time constraint/missing knowledge

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions