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

fix(ts): handle NextRequest type #4472

Merged
merged 4 commits into from Apr 28, 2022
Merged

fix(ts): handle NextRequest type #4472

merged 4 commits into from Apr 28, 2022

Conversation

ubbe-xyz
Copy link
Collaborator

@ubbe-xyz ubbe-xyz commented Apr 26, 2022

馃挕 Reasoning

Following the merge of this PR #4402, the build got broken 馃敟

That's because the getToken() implementation assumed the req object passed to it was an instance of NextApiRequest. However, the new middleware implementation:

https://github.com/nextauthjs/next-auth/blob/main/packages/next-auth/src/next/middleware.ts#L56-L84

is calling this function with a req object which is an instance of NextRequest.

At the end of the day:

const token = getToken({ req })

is only interested in cookies and headers in the req object supplied to it. It happens though that headers are different in NextApiRequest and NextRequest... in NextApiRequest it'll be IncomingHttpHeaders while in NextRequest it'll be Headers and both are read differently...

Random thought

Was getToken() working before when not called in the context of an API route?

// my-page.tsx
export async function getServerSideProps(context) {
  const token = getToken({ req: context.req })
  // ...

馃Б Checklist

  • [ ] Documentation
  • [ ] Tests
  • Ready to be merged

馃師 Affected issues

None

@vercel
Copy link

vercel bot commented Apr 26, 2022

The latest updates on your projects. Learn more about Vercel for Git 鈫楋笌

1 Ignored Deployment
Name Status Preview Updated
next-auth 猬滐笍 Ignored (Inspect) Apr 26, 2022 at 0:16AM (UTC)

@github-actions github-actions bot added the core Refers to `@auth/core` label Apr 26, 2022
Copy link
Member

@balazsorban44 balazsorban44 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks!

@balazsorban44 balazsorban44 changed the title fix(jwt): handle NextRequest type fix(ts): handle NextRequest type Apr 26, 2022
@github-actions github-actions bot added the client Client related code label Apr 26, 2022
@balazsorban44 balazsorban44 merged commit fb4bbc3 into main Apr 28, 2022
@balazsorban44 balazsorban44 deleted the fix/types branch April 28, 2022 09:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
client Client related code core Refers to `@auth/core`
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants