Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

getSession in API takes 5-10 seconds in a new project #3301

Closed
davudk opened this issue Nov 29, 2021 · 1 comment
Closed

getSession in API takes 5-10 seconds in a new project #3301

davudk opened this issue Nov 29, 2021 · 1 comment
Labels
duplicate This issue or pull request already exists question Ask how to do something or how something works

Comments

@davudk
Copy link

davudk commented Nov 29, 2021

Question 馃挰

The title says it all..

I am trying to use getSession({ req }) on the server side and it's taking way too long.

Why is it taking so long? I didn't flag it as bug since I might have overlooked something.

Other info

I've hit this test API on the client side (latest Chrome and Safari) using axios and also using Postman (no cookies were passed).

The result is that it regularly takes 4-8 seconds to complete.

This delay is only present when deployed onto Vercel. When running locally (using vercel dev) there is no delay and everything is alright.

For reference, here is the test API on my sample deployment (hit this in Postman with a GET request):
https://gbs-website-aybet3xkf-eagle-logistics.vercel.app/api/test

Image for reference:

image

The session in the response is expectedly null.

Version: 3.29.0

How to reproduce 鈽曪笍

Here are the relevant files:

pages/api/auth/[...nextauth].ts

import NextAuth, { NextAuthOptions } from 'next-auth';
import Providers from 'next-auth/providers';

const authOptions: NextAuthOptions = {
    providers: [
        Providers.Credentials({
            credentials: {
                username: { label: "Username", type: "text", placeholder: "jsmith" },
                password: { label: "Password", type: "password" }
            },
            async authorize(credentials, req) {
                return null;
            }
        }),
    ]
};

export default NextAuth(authOptions);

pages/api/test.ts

import type { NextApiRequest, NextApiResponse } from 'next';
import { getSession } from 'next-auth/client';

export default async (req: NextApiRequest, res: NextApiResponse) => {
    console.log('session load start:', new Date().toISOString());
    const session = await getSession({ req });
    console.log('session load end:', new Date().toISOString());

    res.status(200).json({ session });
}
@davudk davudk added the question Ask how to do something or how something works label Nov 29, 2021
@balazsorban44
Copy link
Member

Duplicate of #1535

@balazsorban44 balazsorban44 marked this as a duplicate of #1535 Nov 29, 2021
@balazsorban44 balazsorban44 added the duplicate This issue or pull request already exists label Nov 29, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
duplicate This issue or pull request already exists question Ask how to do something or how something works
Projects
None yet
Development

No branches or pull requests

2 participants