-
Notifications
You must be signed in to change notification settings - Fork 27.4k
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
Use new @clerk/nextjs package in with-clerk example, update Next.js authentication docs #28906
Conversation
…hentication API Routes
docs/authentication.md
Outdated
import { withSession } from '@clerk/nextjs/api' | ||
|
||
// Use withSession to decorate `req` with a session object | ||
export default withSession((req, res) => { |
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.
Could we make this provider agnostic? We'd like to avoid picking favorites here 😄
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.
Yes, definitely. In general, I tried to use the precedent from the with-iron-session
examples above - talking generically about the pattern but leveraging a specific example.
I just added a commit that obscures the import:
7a57cd4
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.
It's still referencing Clerk below - I've tried to keep this provider agnostic, with iron session being an OSS library. Can we use that as the example and ensure the code snippet is reflected in the example?
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.
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.
Ok, just pushed an update with the linked example and re-ran linters.
Lmk if there are any other issues!
There's a catch-22 here. Next.js doesn't provide a standardized interface for authentication providers to adhere to, so no two providers work alike. So far, the Authentication docs have used generic copywriting about the available patterns, but specific examples from a single provider. The single provider used for the first two examples is
https://nextjs.org/docs/authentication#authenticating-statically-generated-pages In adding an example about Authenticating API routes, I used a Clerk example, but tried to use the precedent from What do you think this is the best path forward here? |
Hey, taking this over! We switched the example to Let me know if we need to make any more changes to this PR, thanks @leerob :) |
If you'd like to get this merged faster, could we break up the example change and the docs change? The docs will still need some revisions. |
Failing test suitesCommit: 132f958 test/integration/create-next-app/index.test.js
Expand output● create next app › should allow example with GitHub URL
● create next app › should allow example with GitHub URL and example-path
● create next app › should use --example-path over the file path in the GitHub URL
● create next app › should use npm as the package manager on supplying --use-npm with example
|
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.
Looking great!
Co-authored-by: Lee Robinson <me@leerob.io>
Documentation / Examples
This PR makes two updates.
1. Update the
with-clerk
example to use a newly released@clerk/nextjs
packagePreviously, Clerk and Next.js required a combination of
@clerk/clerk-react
(for react) and@clerk/clerk-sdk-node
(for api routes). We combined the functionality into a single, Next.js-specific package to provide a better developer experience around installation and imports.2. Update the Next.js Authentication docs to add an example of API route authentication
Currently, the authentication docs only provide examples for adding authentication to Pages (both with static generation and server-side rendering). This PR adds an example for authenticating an API route.