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: update documentation for version 2.5.0 of the Next.js SDK #305

Merged
merged 6 commits into from
Feb 7, 2025

Conversation

Yoshify
Copy link
Contributor

@Yoshify Yoshify commented Dec 20, 2024

The upcoming 2.5.0 release of the Next.js SDK makes middleware significantly more important - it's now essential for efficient token refreshes.

To signify this, the Middleware section has been moved up from the bottom of the page towards the getting started/configuration section and wording has been changed to describe why it's a requirement.

The middleware matchers have been updated to the new 2.5.0 format as well.

IMPORTANT We should hold off on merging this until version 2.5.0 of the SDK has been released.

Summary by CodeRabbit

Summary by CodeRabbit

  • New Features

    • Introduced a new section in the documentation for customizing Kinde Auth API paths.
    • Added a new section on refreshing Kinde data with guidance on token updates.
  • Documentation

    • Expanded explanations on setting up middleware and route protection, including detailed instructions and code examples.
    • Clarified how to opt routes out of middleware protection and provided additional middleware configuration options.

The upcoming 2.5.0 release of the Next.js SDK makes middleware significantly more important - it's now essential for efficient token refreshes.

To signify this, the Middleware section has been moved up from the bottom of the page towards the getting started/configuration section and wording has been change to denote that it's now a requirement, not optional.

The middleware matchers have been updated to the new 2.5.0 format as well.
Copy link
Contributor

coderabbitai bot commented Dec 20, 2024

Walkthrough

The pull request introduces enhancements to the documentation for the Kinde Auth SDK for Next.js. It adds a new section on customizing API paths, detailing how to set environment variables for various authentication routes. The middleware setup section has been expanded to include instructions for creating a middleware.ts file and utilizing the withAuth helper function. Additional clarifications on opting routes out of middleware protection and a new section on refreshing Kinde data have also been included.

Changes

File Change Summary
src/content/docs/developer-tools/sdks/backend/nextjs-sdk.mdx Added sections on "Customising Kinde Auth API paths" and "Refreshing Kinde data." Expanded "Set up middleware" section with instructions for creating middleware.ts and using withAuth. Clarified opting routes out of middleware protection and added middleware options. New methods middleware(req) and config added in middleware.ts.

Possibly related PRs

Suggested reviewers

  • marcosmartini
  • DanielRivers

Poem

🐰 In the land of code where rabbits play,
Middleware whispers, guiding the way.
Custom paths set, tokens refreshed,
Next.js dances, our dreams are enmeshed!
Hopping through routes, secure and bright,
A joyful leap into the coding night! ✨🔒


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@github-actions github-actions bot added the sdk label Dec 20, 2024
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (2)
src/content/docs/developer-tools/sdks/backend/nextjs-sdk.mdx (2)

81-87: Improve clarity and grammar in the middleware introduction.

The introduction could be clearer with some minor adjustments:

Apply these changes to improve readability:

-Middleware is used to protect routes in your Next.js app, and is a requirement for a seamless authentication experience.
+Middleware is used to protect routes in your Next.js app and is a requirement for a seamless authentication experience.

-We provide a `withAuth` helper that will protect routes covered by the matcher. If the user is not authenticated then they are redirected to login and once they have logged in they will be redirected back to the protected page which they should now have access to.
+We provide a `withAuth` helper that will protect routes covered by the matcher. If the user is not authenticated, they are redirected to log in, and once they have logged in, they will be redirected back to the protected page they should now have access to.
🧰 Tools
🪛 LanguageTool

[typographical] ~83-~83: Consider adding a comma.
Context: ...atcher. If the user is not authenticated then they are redirected to login and once t...

(IF_THEN_COMMA)


[misspelling] ~83-~83: Did you mean the verb “log in” instead of the noun ‘login’?
Context: ...thenticated then they are redirected to login and once they have logged in they will ...

(LOG_IN)


[grammar] ~87-~87: The word “opt-out” is a noun. The verb is spelled with a space.
Context: ... all routes will be protected. You must opt-out public routes - see [opting routes out ...

(NOUN_VERB_CONFUSION)


87-87: Fix verb usage in the public routes section.

The hyphenated form "opt-out" is being used as a verb.

Apply this change:

-You must opt-out public routes
+You must opt out public routes
🧰 Tools
🪛 LanguageTool

[grammar] ~87-~87: The word “opt-out” is a noun. The verb is spelled with a space.
Context: ... all routes will be protected. You must opt-out public routes - see [opting routes out ...

(NOUN_VERB_CONFUSION)

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b4b14d4 and fb85b0f.

📒 Files selected for processing (1)
  • src/content/docs/developer-tools/sdks/backend/nextjs-sdk.mdx (1 hunks)
🧰 Additional context used
🪛 LanguageTool
src/content/docs/developer-tools/sdks/backend/nextjs-sdk.mdx

[typographical] ~83-~83: Consider adding a comma.
Context: ...atcher. If the user is not authenticated then they are redirected to login and once t...

(IF_THEN_COMMA)


[misspelling] ~83-~83: Did you mean the verb “log in” instead of the noun ‘login’?
Context: ...thenticated then they are redirected to login and once they have logged in they will ...

(LOG_IN)


[grammar] ~87-~87: The word “opt-out” is a noun. The verb is spelled with a space.
Context: ... all routes will be protected. You must opt-out public routes - see [opting routes out ...

(NOUN_VERB_CONFUSION)

🔇 Additional comments (2)
src/content/docs/developer-tools/sdks/backend/nextjs-sdk.mdx (2)

99-111: Code examples are well-structured and comprehensive.

The middleware code examples effectively demonstrate:

  • Basic middleware setup with proper matcher configuration
  • Route protection with callback functions
  • Configuration options for public paths and authorization

Also applies to: 118-129, 136-152, 164-186


79-187: Documentation successfully reflects the increased importance of middleware.

The middleware section effectively communicates its essential role in the SDK v2.5.0, aligning with the PR objectives. The documentation provides clear guidance on setup, configuration, and best practices.

🧰 Tools
🪛 LanguageTool

[typographical] ~83-~83: Consider adding a comma.
Context: ...atcher. If the user is not authenticated then they are redirected to login and once t...

(IF_THEN_COMMA)


[misspelling] ~83-~83: Did you mean the verb “log in” instead of the noun ‘login’?
Context: ...thenticated then they are redirected to login and once they have logged in they will ...

(LOG_IN)


[grammar] ~87-~87: The word “opt-out” is a noun. The verb is spelled with a space.
Context: ... all routes will be protected. You must opt-out public routes - see [opting routes out ...

(NOUN_VERB_CONFUSION)

Also discuss limitations about the refreshTokens utility in Next.js
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (3)
src/content/docs/developer-tools/sdks/backend/nextjs-sdk.mdx (3)

81-87: Improve clarity of middleware introduction

The introduction to middleware could be clearer with better punctuation and grammar:

-Middleware is used to protect routes in your Next.js app, and is a requirement for a seamless authentication experience.
+Middleware is used to protect routes in your Next.js app and is a requirement for a seamless authentication experience.

-We provide a `withAuth` helper that will protect routes covered by the matcher. If the user is not authenticated then they are redirected to login and once they have logged in they will be redirected back to the protected page which they should now have access to.
+We provide a `withAuth` helper that will protect routes covered by the matcher. If the user is not authenticated, they are redirected to log in, and once they have logged in, they will be redirected back to the protected page which they should now have access to.

-This means that by default, all routes will be protected. You must opt-out public routes - see [opting routes out of middleware protection](#opting-routes-out-of-middleware-protection) for more information.
+This means that by default, all routes will be protected. You must opt out public routes - see [opting routes out of middleware protection](#opting-routes-out-of-middleware-protection) for more information.
🧰 Tools
🪛 LanguageTool

[typographical] ~83-~83: Consider adding a comma.
Context: ...atcher. If the user is not authenticated then they are redirected to login and once t...

(IF_THEN_COMMA)


[misspelling] ~83-~83: Did you mean the verb “log in” instead of the noun ‘login’?
Context: ...thenticated then they are redirected to login and once they have logged in they will ...

(LOG_IN)


[grammar] ~87-~87: The word “opt-out” is a noun. The verb is spelled with a space.
Context: ... all routes will be protected. You must opt-out public routes - see [opting routes out ...

(NOUN_VERB_CONFUSION)


97-111: Add explanatory comments to middleware configuration example

The middleware configuration example would benefit from more detailed comments explaining the matcher pattern:

 export default function middleware(req) {
   return withAuth(req);
 }

 export const config = {
   matcher: [
-    // Run on everything but Next internals and static files
+    // Matches all paths except:
+    // 1. _next (Next.js internals)
+    // 2. Static files:
+    //    - html, css, js, json
+    //    - images (jpg, jpeg, webp, png, gif, svg)
+    //    - fonts (ttf, woff, woff2)
+    //    - other assets (ico, csv, doc, docx, xls, xlsx, zip, webmanifest)
     '/((?!_next|[^?]*\\.(?:html?|css|js(?!on)|jpe?g|webp|png|gif|svg|ttf|woff2?|ico|csv|docx?|xlsx?|zip|webmanifest)).*)',
   ]
 };

1454-1472: Enhance token refresh section structure

The token refresh section would be clearer with better formatting and additional context:

 ## Refreshing Kinde data

-Our middleware will automatically refresh the tokens in your session in the background. 
+### Automatic refresh
+The middleware automatically refreshes the tokens in your session in the background. 

+### Manual refresh
 Sometimes, you may want to refresh these tokens yourself. An example of this is when you update Kinde data via the UI or with the Management API. 

 To have these updates immediately reflected in your app, you will need to get the most up-to-date Kinde data and then refresh the tokens in your session.

+### Usage
 To get the most up-to-date Kinde data in your session, use the `refreshTokens` helper function provided by `getKindeServerSession`.

 <Aside>
-**Important!** Due to limitations in Next.js, this will only work in a route handler or server action.
+**Important!** Due to Next.js limitations, this will only work in:
+- Route handlers
+- Server actions
 </Aside>

+### Example
 ```tsx
 'use server'
 const { refreshTokens } = getKindeServerSession();

 const handleRefresh = async () => {
   await refreshTokens();
 }

 ...

 <button onClick={handleRefresh}>Get up to date data</button>

</blockquote></details>

</blockquote></details>

<details>
<summary>📜 Review details</summary>

**Configuration used: CodeRabbit UI**
**Review profile: CHILL**
**Plan: Pro**

<details>
<summary>📥 Commits</summary>

Reviewing files that changed from the base of the PR and between fb85b0fc8f7235fb6f545caa04e30dbe46c8ca18 and 63e2977b77f8bf9ec1256faac65ecbcc4a36ac86.

</details>

<details>
<summary>📒 Files selected for processing (1)</summary>

* `src/content/docs/developer-tools/sdks/backend/nextjs-sdk.mdx` (2 hunks)

</details>

<details>
<summary>🧰 Additional context used</summary>

<details>
<summary>🪛 LanguageTool</summary>

<details>
<summary>src/content/docs/developer-tools/sdks/backend/nextjs-sdk.mdx</summary>

[typographical] ~83-~83: Consider adding a comma.
Context: ...atcher. If the user is not authenticated then they are redirected to login and once t...

(IF_THEN_COMMA)

---

[misspelling] ~83-~83: Did you mean the verb “log in” instead of the noun ‘login’?
Context: ...thenticated then they are redirected to login and once they have logged in they will ...

(LOG_IN)

---

[grammar] ~87-~87: The word “opt-out” is a noun. The verb is spelled with a space.
Context: ... all routes will be protected. You must opt-out public routes - see [opting routes out ...

(NOUN_VERB_CONFUSION)

</details>

</details>

</details>

<details>
<summary>🔇 Additional comments (1)</summary>

<details>
<summary>src/content/docs/developer-tools/sdks/backend/nextjs-sdk.mdx (1)</summary>

Line range hint `79-1472`: **Documentation updates align with version 2.5.0 requirements**

The documentation changes effectively communicate the increased importance of middleware in version 2.5.0, particularly its essential role in token refreshes. The restructuring and additional explanations provide clear guidance for users upgrading to the new version.

<details>
<summary>🧰 Tools</summary>

<details>
<summary>🪛 LanguageTool</summary>

[typographical] ~83-~83: Consider adding a comma.
Context: ...atcher. If the user is not authenticated then they are redirected to login and once t...

(IF_THEN_COMMA)

---

[misspelling] ~83-~83: Did you mean the verb “log in” instead of the noun ‘login’?
Context: ...thenticated then they are redirected to login and once they have logged in they will ...

(LOG_IN)

---

[grammar] ~87-~87: The word “opt-out” is a noun. The verb is spelled with a space.
Context: ... all routes will be protected. You must opt-out public routes - see [opting routes out ...

(NOUN_VERB_CONFUSION)

---

[style] ~190-~190: Try using a synonym here to strengthen your writing.
Context: ...p in the Kinde Auth Provider. This will give you access to the Kinde Auth data in your a...

(GIVE_PROVIDE)

</details>

</details>

</details>

</details>

</details>

<!-- This is an auto-generated comment by CodeRabbit for review status -->

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (3)
src/content/docs/developer-tools/sdks/backend/nextjs-sdk.mdx (3)

83-87: Add comma for better readability

The sentence structure needs improvement for clarity.

-We provide a `withAuth` helper that will protect routes covered by the matcher. If the user is not authenticated then they are redirected to login and once they have logged in they will be redirected back to the protected page which they should now have access to.
+We provide a `withAuth` helper that will protect routes covered by the matcher. If the user is not authenticated, they are redirected to log in, and once they have logged in, they will be redirected back to the protected page which they should now have access to.
🧰 Tools
🪛 LanguageTool

[typographical] ~83-~83: Consider adding a comma.
Context: ...atcher. If the user is not authenticated then they are redirected to login and once t...

(IF_THEN_COMMA)


[misspelling] ~83-~83: Did you mean the verb “log in” instead of the noun ‘login’?
Context: ...thenticated then they are redirected to login and once they have logged in they will ...

(LOG_IN)


[grammar] ~87-~87: The word “opt-out” is a noun. The verb is spelled with a space.
Context: ... all routes will be protected. You must opt-out public routes - see [opting routes out ...

(NOUN_VERB_CONFUSION)


87-87: Fix hyphenation in verb form

The term "opt-out" is incorrectly hyphenated when used as a verb.

-You must opt-out public routes
+You must opt out public routes
🧰 Tools
🪛 LanguageTool

[grammar] ~87-~87: The word “opt-out” is a noun. The verb is spelled with a space.
Context: ... all routes will be protected. You must opt-out public routes - see [opting routes out ...

(NOUN_VERB_CONFUSION)


1456-1470: Enhance the token refresh documentation

The explanation about token refreshing could be more comprehensive.

-Our middleware will automatically refresh the tokens in your session in the background. 

-Sometimes, you may want to refresh these tokens yourself. An example of this is when you update Kinde data via the UI or with the Management API. 

-To have these updates immediately reflected in your app, you will need to get the most up-to-date Kinde data and then refresh the tokens in your session.

-To get the most up-to-date Kinde data in your session, use the `refreshTokens` helper function provided by `getKindeServerSession`.

-<Aside>

-**Important!** 

-Due to limitations in Next.js, this will only work in a route handler or server action.

-</Aside>
+Our middleware automatically refreshes the tokens in your session in the background. However, there are scenarios where you might need to manually refresh these tokens:

+1. After updating Kinde data through the UI
+2. After making changes via the Management API
+3. When you need immediate reflection of changes in your app

+To manually refresh tokens and get the most up-to-date Kinde data in your session, use the `refreshTokens` helper function provided by `getKindeServerSession`.

+<Aside type="warning">

+**Important Next.js Limitation** 

+Due to Next.js's architecture, the `refreshTokens` function can only be called from:
+- Route handlers
+- Server actions
+
+It will not work in other contexts.

+</Aside>
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 63e2977 and 592b086.

📒 Files selected for processing (1)
  • src/content/docs/developer-tools/sdks/backend/nextjs-sdk.mdx (2 hunks)
🧰 Additional context used
🪛 LanguageTool
src/content/docs/developer-tools/sdks/backend/nextjs-sdk.mdx

[typographical] ~83-~83: Consider adding a comma.
Context: ...atcher. If the user is not authenticated then they are redirected to login and once t...

(IF_THEN_COMMA)


[misspelling] ~83-~83: Did you mean the verb “log in” instead of the noun ‘login’?
Context: ...thenticated then they are redirected to login and once they have logged in they will ...

(LOG_IN)


[grammar] ~87-~87: The word “opt-out” is a noun. The verb is spelled with a space.
Context: ... all routes will be protected. You must opt-out public routes - see [opting routes out ...

(NOUN_VERB_CONFUSION)

🔇 Additional comments (1)
src/content/docs/developer-tools/sdks/backend/nextjs-sdk.mdx (1)

Line range hint 79-1474: Documentation updates align with version 2.5.0 changes

The documentation changes effectively communicate the increased importance of middleware and its essential role in token refreshes for version 2.5.0. The restructuring and rewording make the requirements clearer for users.

🧰 Tools
🪛 LanguageTool

[typographical] ~83-~83: Consider adding a comma.
Context: ...atcher. If the user is not authenticated then they are redirected to login and once t...

(IF_THEN_COMMA)


[misspelling] ~83-~83: Did you mean the verb “log in” instead of the noun ‘login’?
Context: ...thenticated then they are redirected to login and once they have logged in they will ...

(LOG_IN)


[grammar] ~87-~87: The word “opt-out” is a noun. The verb is spelled with a space.
Context: ... all routes will be protected. You must opt-out public routes - see [opting routes out ...

(NOUN_VERB_CONFUSION)


[style] ~190-~190: Try using a synonym here to strengthen your writing.
Context: ...p in the Kinde Auth Provider. This will give you access to the Kinde Auth data in your a...

(GIVE_PROVIDE)

Comment on lines +81 to +82
Middleware is used to protect routes in your Next.js app, and is a requirement for a seamless authentication experience.

Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Strengthen the requirement statement

The current wording doesn't fully emphasize that middleware is now a requirement in version 2.5.0. Consider revising to make this clearer.

-Middleware is used to protect routes in your Next.js app, and is a requirement for a seamless authentication experience.
+Middleware is a required component in version 2.5.0+ for handling authentication and token refreshes in your Next.js app. It is no longer optional.
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
Middleware is used to protect routes in your Next.js app, and is a requirement for a seamless authentication experience.
Middleware is a required component in version 2.5.0+ for handling authentication and token refreshes in your Next.js app. It is no longer optional.

Copy link
Collaborator

@clairekinde11 clairekinde11 left a comment

Choose a reason for hiding this comment

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

Couple of minor copyedit things. Otherwise lgtm :)

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (2)
src/content/docs/developer-tools/sdks/backend/nextjs-sdk.mdx (2)

79-86: Enhanced Middleware Requirement and Clarity
The new "Set up middleware" section effectively introduces the updated requirement for middleware in version 2.5.0. To improve clarity and adhere to best writing practices, consider revising the sentence that describes the redirection behavior. For instance, instead of:
"If the user is not authenticated then they are redirected to login and once they have logged in they will be redirected back to the protected page which they should now have access to."
you could use:
"If the user is not authenticated, they are redirected to log in, and once authenticated, they will be redirected back to the protected page, to which they now have access."

Additionally, change “opt-out public routes” to “opt routes out of protection” to correct the verb usage.

Suggested diff:

-If the user is not authenticated then they are redirected to login and once they have logged in they will be redirected back to the protected page which they should now have access to.
+If the user is not authenticated, they are redirected to log in, and once authenticated, they will be redirected back to the protected page, to which they now have access.
-This means that by default, all routes will be protected. You must opt-out public routes - see [opting routes out of middleware protection](#opting-routes-out-of-middleware-protection) for more information.
+This means that by default, all routes will be protected. You must opt routes out of protection - see [opting routes out of middleware protection](#opting-routes-out-of-middleware-protection) for more information.
🧰 Tools
🪛 LanguageTool

[typographical] ~83-~83: Consider adding a comma.
Context: ...atcher. If the user is not authenticated then they are redirected to login and once t...

(IF_THEN_COMMA)


[misspelling] ~83-~83: Did you mean the verb “log in” instead of the noun ‘login’?
Context: ...thenticated then they are redirected to login and once they have logged in they will ...

(LOG_IN)


154-183: Additional Middleware Options and Security Consideration
The "Additional middleware options" section provides a comprehensive example of how to pass extra configuration to the middleware, such as isReturnToCurrentPage, loginPage, publicPaths, and a custom isAuthorized function. One minor recommendation is to update the logging inside the middleware callback to avoid potentially exposing sensitive token details. For production usage, it is advisable to either remove or modify the logging statement.

Suggested diff:

-export default withAuth(
-  async function middleware(req) {
-    console.log("look at me", req.kindeAuth);
-  },
+export default withAuth(
+  async function middleware(req) {
+    // For demonstration purposes only. Avoid logging sensitive token details in production.
+    console.log("Middleware invoked. Token details:", req.kindeAuth);
+  },
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 592b086 and 7f9acba.

📒 Files selected for processing (1)
  • src/content/docs/developer-tools/sdks/backend/nextjs-sdk.mdx (2 hunks)
🧰 Additional context used
🪛 LanguageTool
src/content/docs/developer-tools/sdks/backend/nextjs-sdk.mdx

[typographical] ~83-~83: Consider adding a comma.
Context: ...atcher. If the user is not authenticated then they are redirected to login and once t...

(IF_THEN_COMMA)


[misspelling] ~83-~83: Did you mean the verb “log in” instead of the noun ‘login’?
Context: ...thenticated then they are redirected to login and once they have logged in they will ...

(LOG_IN)


[grammar] ~87-~87: The word “opt-out” is a noun. The verb is spelled with a space.
Context: ... all routes will be protected. You must opt-out public routes - see [opting routes out ...

(NOUN_VERB_CONFUSION)

🔇 Additional comments (3)
src/content/docs/developer-tools/sdks/backend/nextjs-sdk.mdx (3)

97-110: Middleware Configuration Code Snippet
The provided code snippet for creating the middleware.ts file is clear and concise. It correctly imports withAuth and sets up a matcher that excludes Next.js internals and static files. The example clearly demonstrates the basic implementation with no issues.


113-127: Route Protection with Callback Function
This example clearly demonstrates how to use the withAuth helper along with an asynchronous callback function that accesses the req.kindeAuth object. It effectively illustrates how to customize behavior after authorization. Just ensure that including a console.log of token details is acceptable in your documentation context.


131-150: Opting Routes Out of Middleware Protection
The snippet for opting routes out of middleware protection is well structured. It shows how to use the publicPaths option to exempt specific routes (e.g., /blog) from authentication, which is highly valuable for developers. The example is straightforward and communicates the intended functionality clearly.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (2)
src/content/docs/developer-tools/sdks/backend/nextjs-sdk.mdx (2)

79-106: Enhance API Path Customization Section

The new "Customising Kinde Auth API paths" section clearly explains how to override the default API path and adjust the sub-paths via environment variables. The examples and instructions are concise and easy to follow. One suggestion is to briefly mention that these customizations support the updated behavior in version 2.5.0, so users immediately understand the context of the change.


1482-1510: Clarify and Strengthen the Refresh Tokens Example

The "Refreshing Kinde data" section does a good job explaining why and when you might need to manually refresh tokens. The example using the refreshTokens helper is useful; however, a couple of improvements could make it even clearer:

  1. Consider including an import statement for getKindeServerSession to ensure the snippet is self-contained:

    +import { getKindeServerSession } from "@kinde-oss/kinde-auth-nextjs/server";
  2. The code sample uses a 'use server' directive and shows an onClick handler on a button. Since Next.js server actions are intended to run in route handlers or server action contexts (and not directly as client-side event handlers), it might help to clarify in a comment that this example is meant to be used as a server action (or provide guidance on how to wire it correctly into a client component).

These clarifications will help prevent any confusion about server–client boundaries and ensure that users integrate token refresh actions in a way that complies with Next.js best practices.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 7f9acba and e447d76.

📒 Files selected for processing (1)
  • src/content/docs/developer-tools/sdks/backend/nextjs-sdk.mdx (2 hunks)
🧰 Additional context used
🪛 LanguageTool
src/content/docs/developer-tools/sdks/backend/nextjs-sdk.mdx

[typographical] ~111-~111: Consider adding a comma.
Context: ...atcher. If the user is not authenticated then they are redirected to login and once t...

(IF_THEN_COMMA)


[misspelling] ~111-~111: Did you mean the verb “log in” instead of the noun ‘login’?
Context: ...thenticated then they are redirected to login and once they have logged in they will ...

(LOG_IN)


[grammar] ~115-~115: The word “opt-out” is a noun. The verb is spelled with a space.
Context: ... all routes will be protected. You must opt-out public routes - see [opting routes out ...

(NOUN_VERB_CONFUSION)

@DanielRivers DanielRivers merged commit 75b1d3c into kinde-oss:main Feb 7, 2025
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants