next-auth icon indicating copy to clipboard operation
next-auth copied to clipboard

NextRequest types are wrong after nextjs v12.2.0

Open ThomasLarge opened this issue 3 years ago • 1 comments

Question 💬

CleanShot 2022-09-01 at 15 53 26@2x

On the left are the new types from NextJS and on the Right are the types that getToken are using. When upgrading NextJS passed 12.2.0 the types become incompatible.

CleanShot 2022-09-01 at 15 55 12@2x

This is the type of error when upgrading to NextJS v12.2.5

I believe the fix would be upgrading the nextJS package and making sure the types are updated. I'm more than happy to help out with this if I can be pointed in the right direction for how to get started :)

How to reproduce ☕️

import { getToken } from 'next-auth/jwt';
import { NextResponse, NextRequest } from 'next/server';

export const middleware = async (req: NextRequest) => {

    const token = await getToken({
      req, // Type error here
      secret: process.env.JWT_SECRET,
      secureCookie: secureCookie(),
    });

    ...

  return NextResponse.next();
};

Contributing 🙌🏽

Yes, I am willing to help answer this question in a PR

ThomasLarge avatar Sep 01 '22 15:09 ThomasLarge

I believe bumping next to 12.2.5 in devDependencies should fix it. Feels a bit weird that a devDependencies causes this, so in addition, I think we need same version of next in peerDependencies too 🤔 PR welcomes!

ThangHuuVu avatar Sep 11 '22 03:09 ThangHuuVu

Closed in #5384

balazsorban44 avatar Sep 25 '22 10:09 balazsorban44

Cannot use Next.js 12.3.1 with the latest Next-Auth package version anymore.

npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR!
npm ERR! While resolving: @accelist/[email protected]
npm ERR! Found: [email protected]
npm ERR! node_modules/next
npm ERR!   next@"12.3.1" from the root project
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! peer next@"12.2.5" from [email protected]
npm ERR! node_modules/next-auth
npm ERR!   next-auth@"4.12.0" from the root project
npm ERR!
npm ERR! Fix the upstream dependency conflict, or retry
npm ERR! this command with --force, or --legacy-peer-deps
npm ERR! to accept an incorrect (and potentially broken) dependency resolution.
npm ERR!

ryanelian avatar Sep 26 '22 09:09 ryanelian