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

Improve auth docs #63140

Merged
merged 28 commits into from
Apr 16, 2024
Merged

Improve auth docs #63140

merged 28 commits into from
Apr 16, 2024

Conversation

delbaoliveira
Copy link
Contributor

@delbaoliveira delbaoliveira commented Mar 11, 2024

Clarify best practices for implementing authentication in Next.js, including what Next.js and React features to use and when. With the minimum number of tools, we'll try to teach authentication from first principles (simple password + email), then recommend Next.js-compatible libraries, and further resources.

Authentication:

  • Forms and Server Actions
  • Server-side form validation and early returns
  • Form errors with useFormStatus()
  • Pending states with useFormState()

Session Management:

  • Stateless Sessions
  • Database Sessions
  • Setting cookies on the server
    • cookies()
  • sever-only

Authorization:

  • Optimistic vs. secure checks
  • Middleware for optimistic checks
    • Performance caveats - what not to do
  • DAL - centralizing data requests, verifying auth state close to the data source
    • redirect()
  • DTO - returning the minimum data, preventing exposure on the client
  • Recommendations for:
    • Server Components
      • Partial rendering and layout caveats
    • Server Actions
    • Route Handlers

DX Content: "What is the right way to do authentication?".
Test Example: vercel-labs/app-router-auth#1

This is how I currently visualize it, this diagram is not meant for users, but to help clarify our current understanding. What am I missing?

CleanShot 2024-03-22 at 14 27 24@2x

@delbaoliveira delbaoliveira requested review from a team as code owners March 11, 2024 14:06
@delbaoliveira delbaoliveira requested review from ismaelrumzan and StephDietz and removed request for a team March 11, 2024 14:06
@delbaoliveira delbaoliveira marked this pull request as draft March 11, 2024 14:06
Copy link
Contributor

github-actions bot commented Mar 11, 2024

Hi there 👋

It looks like this PR introduces broken links to the docs, please take a moment to fix them before merging:

Broken link Type File
#updating-or-extending-the-session hash /docs/02-app/01-building-your-application/09-authentication/index.mdx

Thank you 🙏

@cpeaustriajc
Copy link

cpeaustriajc commented Mar 12, 2024

Can I suggest adding The Copenhagen Book in the Further Reading section?

https://thecopenhagenbook.com/

@delbaoliveira
Copy link
Contributor Author

Thank you for the suggestion @fujiwaracj 🙏🏼 Been using it as a reference for an example, it's helpful.

@delbaoliveira delbaoliveira marked this pull request as ready for review March 22, 2024 15:45
Copy link
Member

@leerob leerob left a comment

Choose a reason for hiding this comment

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

Good to merge and iterate if we want 😄

@delbaoliveira delbaoliveira changed the title WIP: Improve auth docs Improve auth docs Apr 16, 2024
@delbaoliveira delbaoliveira merged commit 3cf4183 into canary Apr 16, 2024
33 of 38 checks passed
@delbaoliveira delbaoliveira deleted the docs-id9w branch April 16, 2024 16:55

### Protecting Routes with Middleware

Choose a reason for hiding this comment

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

@delbaoliveira Hi, why was the "Protecting Routes with Middleware" section removed?

Copy link
Contributor Author

@delbaoliveira delbaoliveira Apr 17, 2024

Choose a reason for hiding this comment

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

Hey, it's now called Optimistic checks with Middleware.

leerob pushed a commit that referenced this pull request Apr 18, 2024
@github-actions github-actions bot added the locked label May 3, 2024
@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 3, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants