Skip to content

Auth.js Guide Created #7064

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

Merged
merged 7 commits into from
Aug 13, 2025
Merged

Auth.js Guide Created #7064

merged 7 commits into from
Aug 13, 2025

Conversation

aidankmcalister
Copy link
Member

@aidankmcalister aidankmcalister commented Aug 7, 2025

Summary by CodeRabbit

  • New Features

    • Added a comprehensive guide for integrating Auth.js with Prisma and Next.js (App Router) using PostgreSQL, with step-by-step setup, middleware, auth helpers, and runnable examples.
    • Included ready-to-use sign-in/sign-out components and auth helpers plus an example app page demonstrating auth-aware UI and user data display.
  • Documentation

    • Added the new guide to the "Integration Solutions" sidebar.
  • Chores

    • Added "Authjs" to spellcheck configuration.

Copy link
Contributor

github-actions bot commented Aug 7, 2025

Dangerous URL check

No absolute URLs to prisma.io/docs found.
No local URLs found.

Copy link
Contributor

github-actions bot commented Aug 7, 2025

Copy link
Contributor

github-actions bot commented Aug 7, 2025

Redirect check

This PR probably requires the following redirects to be added to static/_redirects:

  • This PR does not change any pages in a way that would require a redirect.

Copy link

cloudflare-workers-and-pages bot commented Aug 7, 2025

Deploying docs with  Cloudflare Pages  Cloudflare Pages

Latest commit: bafa32e
Status: ✅  Deploy successful!
Preview URL: https://48223a36.docs-51g.pages.dev
Branch Preview URL: https://dc-3704-authjs-nextjs-guide.docs-51g.pages.dev

View logs

Copy link

coderabbitai bot commented Aug 7, 2025

Walkthrough

Added a new guide documenting wiring Auth.js with Prisma and Next.js (App Router) using PostgreSQL, plus sidebar registration and a cSpell entry for "Authjs". The guide includes setup steps, Prisma schema/client, Auth.js adapter and API route, middleware, UI components, and runtime/testing notes.

Changes

Cohort / File(s) Change Summary
New Guide (MDX)
content/800-guides/350-authjs-nextjs.mdx
Added a step-by-step guide covering Prisma + Auth.js + Next.js (App Router) integration with code samples (schema, client, adapter, middleware, components, run instructions).
Sidebar Update
sidebars.ts
Added "guides/authjs-nextjs" entry to the "Integration Solutions" section of the docs sidebar.
Spell Checker
cSpell.json
Added "Authjs" to the custom dictionary to avoid spelling warnings.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant NextApp as Next.js App
    participant AuthJS as Auth.js
    participant Prisma
    participant Postgres as PostgreSQL

    User->>NextApp: Request page
    NextApp->>AuthJS: auth() check
    AuthJS->>Prisma: Query session/user
    Prisma->>Postgres: Read session/user
    Postgres-->>Prisma: Return data
    Prisma-->>AuthJS: Return user/session
    AuthJS-->>NextApp: Auth state

    alt Not authenticated
        User->>NextApp: Click SignIn
        NextApp->>AuthJS: signIn(provider)
        AuthJS->>Prisma: Create account/session
        Prisma->>Postgres: Write records
    else Authenticated
        User->>NextApp: Click SignOut
        NextApp->>AuthJS: signOut()
        AuthJS->>Prisma: Delete session
        Prisma->>Postgres: Delete records
    end
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes


📜 Recent review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 33b6784 and bafa32e.

📒 Files selected for processing (1)
  • content/800-guides/350-authjs-nextjs.mdx (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • content/800-guides/350-authjs-nextjs.mdx
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
  • GitHub Check: Check internal links
  • GitHub Check: runner / linkspector
  • GitHub Check: Lost Pixel
✨ Finishing Touches
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch DC-3704-authjs-nextjs-guide

🪧 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.
    • 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.
  • 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 the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

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

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • 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.

Copy link

coderabbitai bot commented Aug 7, 2025

Caution

No docstrings were generated.

Copy link

@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 (2)
content/800-guides/350-authjs-nextjs.mdx (2)

232-232: Consider mentioning the beta version implications.

Installing next-auth@beta may introduce breaking changes or unstable features. Consider adding a note about this or specifying a more stable version if available.


516-526: Consider adding type safety for session.user.id.

The code accesses session.user?.id without ensuring it exists, which could cause runtime issues if the session user doesn't have an id property.

Apply this diff to add proper type checking:

  if (session) {
+   if (!session.user?.id) {
+     return // or handle this case appropriately
+   }
    user = await prisma.user.findUnique({
      where: {
-       id: session.user?.id,
+       id: session.user.id,
      }
    });
  }
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 23d8d87 and b702f03.

📒 Files selected for processing (2)
  • content/800-guides/350-authjs-nextjs.mdx (1 hunks)
  • sidebars.ts (1 hunks)
🧰 Additional context used
🪛 GitHub Actions: Documentation Checks
content/800-guides/350-authjs-nextjs.mdx

[error] 6-6: CSpell: Unknown word 'authjs' detected.

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: runner / linkspector
  • GitHub Check: Lost Pixel
🔇 Additional comments (8)
sidebars.ts (1)

449-449: LGTM! Sidebar integration is correct.

The new Auth.js guide entry is properly added to the "Integration Solutions" category, following the established pattern and maintaining alphabetical sorting.

content/800-guides/350-authjs-nextjs.mdx (7)

1-9: LGTM! Well-structured metadata.

The front matter includes all necessary metadata fields with appropriate values. The 25-minute completion time is realistic for this comprehensive guide.


74-74: Verify the unusual output path configuration.

The --output ../app/generated/prisma path is unconventional. Typically, Prisma generates the client in node_modules/@prisma/client or a custom path within the project structure.

Ensure this path aligns with the project structure and doesn't cause import issues. The standard approach would be to generate in the default location or use a path like ./generated/client.


188-203: LGTM! Proper Prisma Client setup with Accelerate.

The client setup correctly uses the global singleton pattern to prevent multiple instances in development, and properly integrates the Accelerate extension for Prisma Postgres users.


325-327: LGTM! Minimal and effective middleware setup.

The middleware configuration correctly exports the auth function to protect routes automatically.


337-409: LGTM! Well-structured auth components.

The SignIn and SignOut components are properly implemented with server actions, following Next.js App Router best practices for form handling.


569-595: LGTM! Clear testing instructions.

The testing section provides comprehensive steps for validating the implementation, including using Prisma Studio for database inspection.


11-595: Excellent comprehensive guide with minor improvements needed.

This is a well-structured, thorough guide that effectively demonstrates Auth.js integration with Prisma and Next.js. The step-by-step approach, code examples, and explanations are clear and helpful for developers.

Key strengths:

  • Clear prerequisites and setup instructions
  • Proper separation of concerns between authentication and database layers
  • Good use of modern Next.js patterns (App Router, Server Actions)
  • Comprehensive testing instructions

coderabbitai[bot]
coderabbitai bot previously approved these changes Aug 7, 2025
Copy link
Contributor

github-actions bot commented Aug 7, 2025

Images automagically compressed by Calibre's image-actions

Compression reduced images by 16.1%, saving 62.23 KB.

Filename Before After Improvement Visual comparison
static/img/guides/prisma-authjs-nextjs-cover.png 387.45 KB 325.21 KB -16.1% View diff

206 images did not require optimisation.

coderabbitai[bot]
coderabbitai bot previously approved these changes Aug 7, 2025
coderabbitai[bot]
coderabbitai bot previously approved these changes Aug 7, 2025
Copy link

@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: 2

♻️ Duplicate comments (2)
content/800-guides/350-authjs-nextjs.mdx (2)

6-6: Fix image filename to satisfy spellcheck and consistency

The pipeline previously flagged "authjs". Use the hyphenated filename to avoid the token and match naming.

-image: '/img/guides/prisma-authjs-nextjs-cover.png'
+image: '/img/guides/prisma-auth-js-nextjs-cover.png'

1-612: CSpell: ensure lowercase “authjs” isn’t still flagged

You added “Authjs” to the dictionary, but this doc includes numerous lowercase “authjs” tokens (e.g., project name, image path). CSpell is often case-sensitive; consider adding the lowercase variant or adding a file-level ignore comment.

To verify occurrences:

#!/bin/bash
# Find lowercase 'authjs' occurrences in docs (case-sensitive)
rg -n --hidden -S '\bauthjs\b' content | sed -n '1,200p'

Options:

  • Add both variants to cSpell dictionary: ["Authjs", "authjs"].
  • Or add a file header directive in this MDX: .
🧹 Nitpick comments (3)
content/800-guides/350-authjs-nextjs.mdx (3)

325-327: Limit middleware scope to avoid protecting assets and all routes

Exporting auth as middleware without a matcher applies it broadly. Add a matcher to target only the app routes you want to protect.

 export { auth as middleware } from '@/lib/auth'
+
+// Only protect application routes; allow assets and auth endpoints
+export const config = {
+  matcher: ['/((?!api/auth|_next/static|_next/image|favicon\\.ico).*)'],
+}

Adjust the matcher to your needs (for example, ['/dashboard/:path*']).


375-389: Polish provider label in the button

The UI will render "github" verbatim. Capitalize for brand consistency or map to a friendly label.

-      <button className="bg-neutral-700 text-white p-2 rounded-md">
-        Sign In with {provider}
+      <button className="bg-neutral-700 text-white p-2 rounded-md">
+        Sign In with {(provider === 'github' ? 'GitHub' : provider) ?? 'Provider'}
       </button>

596-599: Use proper brand capitalization (“GitHub”) in text

For consistency and brand correctness, prefer “GitHub”.

-2. Navigate to `http://localhost:3000` in your browser. You should see the home page with a "Sign In with github" button.
+2. Navigate to `http://localhost:3000` in your browser. You should see the home page with a "Sign In with GitHub" button.
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 1f1d51d and 33b6784.

📒 Files selected for processing (1)
  • content/800-guides/350-authjs-nextjs.mdx (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
  • GitHub Check: Check internal links
  • GitHub Check: runner / linkspector
  • GitHub Check: Lost Pixel

coderabbitai[bot]
coderabbitai bot previously approved these changes Aug 11, 2025
Copy link
Member

@nikolasburk nikolasburk left a comment

Choose a reason for hiding this comment

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

the tutorial mostly worked fine but I think it's missing the implementation of the callback route? at least the test didn't work for me in the end ...

@aidankmcalister aidankmcalister merged commit 5ed66d3 into main Aug 13, 2025
12 of 14 checks passed
@aidankmcalister aidankmcalister deleted the DC-3704-authjs-nextjs-guide branch August 13, 2025 11:59
@coderabbitai coderabbitai bot mentioned this pull request Aug 13, 2025
@coderabbitai coderabbitai bot mentioned this pull request Aug 13, 2025
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.

3 participants