-
Notifications
You must be signed in to change notification settings - Fork 559
feat(auth): Next.js App Router support #2106
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(auth): Next.js App Router support #2106
Conversation
This feature brings Next.js App Router support to the Thirdweb Auth package and fixes #2022.
🦋 Changeset detectedLatest commit: 14ba584 The changes in this PR will be included in the next version bump. This PR includes changesets to release 7 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Removed dependencies detected. Learn more about Socket for GitHub ↗︎ 🚮 Removed packages: npm/[email protected] |
Btw, I also brought
|
The below document and code example need to be updated accordingly. |
The function might be used/called in a Next.js component or elsewhere. So it's not always a must to pass a request object. This is a breaking change.
Thanks for the PR! We'll take a look shortly |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks a lot for putting up this PR, super helpful!
As far as approach - rather than replacing the support for auth in pages
directory with app
directory as it is here, we should support both pages
(old code) and app
(new code) since there are users still using both.
The best path here would likely just to create separate exports for each of them - ie the old export could be called ThirdwebAuthPages
and the new one could be called ThirdwebAuthApp
or something like ThirdwebAuth
and ThirdwebAuthRouter
, etc.
So essentially, would just add back the old code and change the export name, and then keep your new code as a separate folder with another export.
Feel free to make this change - or I'll get to it after my current focus (might take a few days/week+)
@adam-maj sure. I will try to find a way to do it 'cause I really need this feature asap :) |
domain: ctx.cookieOptions?.domain, | ||
path: ctx.cookieOptions?.path || "/", | ||
sameSite: ctx.cookieOptions?.sameSite || "none", | ||
expires: new Date(Date.now() + 5 * 1000), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@adam-maj I wonder why setting the cookie expiry to 5 seconds instead of deleting the cookie at that time?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@adam-maj ping
@adam-maj There are a few boring things to cover Pages and App Routers support in the same package. For more information see the below reasons list. I suggest that it'd be better to create a new package (
|
Thanks for the update & comment! Given that many (from what I've seen, most) Next + Auth users are still using the Instead of handling the same routes in one You should be able to keep With that setup, should be able to merge in the PR and get it all build ASAP |
@adam-maj did you review the last commit? |
@hsynlms Thanks - this looks perfect! Have you tested both the router and pages versions? If not I can help with this, an I'll merge ASAP right after. |
@adam-maj I rebuilt the package and tested it with my App Router app. It works! But let's double check and ensure it works properly. So I need your tests too :) |
/release-pr |
Btw @hsynlms one question - what's the reasoning behind the abstract wallets change in |
Signed-off-by: Adam Majmudar <[email protected]>
/release-pr |
@hsynlms Just tested for both app router and pages and works like a charm! Pending merge conflict resolution and the last question, should be good to go and I'll merge 😄 |
Sure! See the below comment. That's why I edited the |
@adam-maj I think the PR is ready to go! |
@hsynlms Perfect, good to go - thanks for putting this together! |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #2106 +/- ##
==========================================
- Coverage 67.51% 67.08% -0.44%
==========================================
Files 291 291
Lines 11016 11016
Branches 1513 1513
==========================================
- Hits 7438 7390 -48
- Misses 2952 3001 +49
+ Partials 626 625 -1 ☔ View full report in Codecov by Sentry. |
Bumps [react-hook-form](https://github.com/react-hook-form/react-hook-form) from 7.48.2 to 7.49.3. - [Release notes](https://github.com/react-hook-form/react-hook-form/releases) - [Changelog](https://github.com/react-hook-form/react-hook-form/blob/master/CHANGELOG.md) - [Commits](react-hook-form/react-hook-form@v7.48.2...v7.49.3) --- updated-dependencies: - dependency-name: react-hook-form dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Nacho Iacovino <[email protected]>
This feature brings Next.js App Router support to the Thirdweb Auth package and fixes #2022.
Problem solved
Thirdweb Auth Next generates API handlers for Next.js Pages Router apps. But it is still not fully compatible with the new Next.js App Router.
Next.js App Router has become stable since v13.4.
In this PR, I kept existing router support which is Pages Router and added compatibility with App Router.
Example usage
Changes made
How to test