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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: custom jwt decode method for middleware #4210

Merged
merged 7 commits into from May 31, 2022

Conversation

hinsxd
Copy link
Contributor

@hinsxd hinsxd commented Mar 17, 2022

Reasoning 💡

As mentioned in #4181, having a custom jwt.decode method in [...nextauth].ts will cause errors in any _middleware.ts when the middleware tries to call getToken() internally without the correct decode method.

Checklist 🧢

  • Added jwt.decode option to middleware and pass it to getToken
  • Added documentation to Configuration > Next.js > Middleware to address the problem
  • Added documentation to Configuration > Options > Override JWT encode and decode methods to link to the above section
  • Tested by hand

Affected issues 🎟

Fixes #4181

@vercel
Copy link

vercel bot commented Mar 17, 2022

This pull request is being automatically deployed with Vercel (learn more).
To see the status of your deployment, click below or on the icon next to each commit.

🔍 Inspect: https://vercel.com/nextauthjs/next-auth/CXk7atmGRymv1LFRfNAZARW8ESQu
✅ Preview: https://next-auth-git-fork-hinsxd-feat-4181-middlewar-a30d7e-nextauthjs.vercel.app

@vercel vercel bot temporarily deployed to Preview March 17, 2022 17:11 Inactive
@github-actions github-actions bot added the core Refers to `@auth/core` label Mar 17, 2022
@ndom91
Copy link
Member

ndom91 commented Mar 20, 2022

Yeah this makes a lot of sense to me - @ThangHuuVu, @lluia what do you think?

Copy link
Member

@ThangHuuVu ThangHuuVu left a comment

Choose a reason for hiding this comment

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

LGTM, I found a typo 🙏

docs/docs/configuration/options.md Outdated Show resolved Hide resolved
@agustif
Copy link

agustif commented Mar 20, 2022

Awesome! I will probably need this as I haven't yet got around implementing my own JWT callback but might want to do so in the future to allow for custom options passing to it, like extended or no expiry date, and some metadata (like a user provided name for the token). I plan to re-use sessions as Personal Access Tokens for an API. and that's how I plan to create such tokens.

Thanks for the pr @hinsxd let's hope it can get merged =)

Co-authored-by: Thang Vu <31528554+ThangHuuVu@users.noreply.github.com>
@vercel vercel bot temporarily deployed to Preview March 20, 2022 21:38 Inactive
@hinsxd
Copy link
Contributor Author

hinsxd commented Mar 20, 2022

@ThangHuuVu Thanks for spotting the typo!

@vercel vercel bot temporarily deployed to Preview March 20, 2022 21:42 Inactive
@ndom91
Copy link
Member

ndom91 commented Mar 22, 2022

Hey so this looks great, however we're going to hold off on merging and releasing a new version for a bit until Balazs is back from break. We appreciate the contribution though and will keep you posted!

@ndom91 ndom91 added the ready Ready to merge label Mar 22, 2022
@vercel vercel bot temporarily deployed to Preview April 4, 2022 08:26 Inactive
@vercel
Copy link

vercel bot commented May 10, 2022

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated
next-auth ✅ Ready (Inspect) Visit Preview May 25, 2022 at 9:04AM (UTC)

@vercel vercel bot temporarily deployed to Preview May 10, 2022 09:26 Inactive
@vercel vercel bot temporarily deployed to Preview May 25, 2022 09:04 Inactive
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.

Thank you! Looks good! 🙌

@balazsorban44 balazsorban44 merged commit 16622f6 into nextauthjs:main May 31, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core Refers to `@auth/core` ready Ready to merge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

MIddleware should accept custom JWT decode method to correctly read custom-signed JWT
5 participants