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

chore(docs): update middleware redirect example #10815

Merged
merged 3 commits into from
May 19, 2024

Conversation

DenilDenilson
Copy link
Contributor

The current example of protecting with Next.js middleware isn't functioning. I propose a new example that works correctly and is easy to understand.

☕️ Reasoning

In the documentation for protecting resources with Next.js middleware, the example code isn't functioning correctly. The 'replace' method replaces the first '/' in the URL (https://...) with 'loginlocalhost:/', which is an error. I've made changes to the code in the documentation to ensure it works properly by using the URL constructor with the base URL and the new pathname. Additionally, I've implemented a new validation to prevent infinite redirects.

🧢 Checklist

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

🎫 Affected issues

📌 Resources

The current example of protecting with Next.js middleware isn't functioning. I propose a new example that works correctly and is easy to understand.
Copy link

vercel bot commented May 4, 2024

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

Name Status Preview Comments Updated (UTC)
auth-docs ❌ Failed (Inspect) May 19, 2024 11:00am
1 Ignored Deployment
Name Status Preview Comments Updated (UTC)
next-auth-docs ⬜️ Ignored (Inspect) Visit Preview May 19, 2024 11:00am

Copy link

vercel bot commented May 4, 2024

@DenilDenilson is attempting to deploy a commit to the authjs Team on Vercel.

A member of the Team first needs to authorize it.

@ndom91 ndom91 changed the title Update protecting Next Middleware Example.mdx chore(docs): update middleware redirect example May 6, 2024
@ndom91
Copy link
Member

ndom91 commented May 6, 2024

Thanks for the cleanup! One small nit, but otherwise LGTM

Copy link
Member

@ndom91 ndom91 left a comment

Choose a reason for hiding this comment

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

Yeah nice improvement, thanks!

@ndom91 ndom91 merged commit ece3f6d into nextauthjs:main May 19, 2024
10 of 13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants