Skip to content

Conversation

@jiashengguo
Copy link
Member

@jiashengguo jiashengguo commented Jun 28, 2025

Summary by CodeRabbit

  • New Features

    • Added a new guide for integrating Better Auth with ZenStack, including setup instructions, organization support, and access policy examples.
  • Documentation

    • Updated sidebar positions for several authentication guides to improve navigation order. No content changes were made to these documents.

@vercel
Copy link

vercel bot commented Jun 28, 2025

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

Name Status Preview Comments Updated (UTC)
zenstack-new-site ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 28, 2025 9:14am

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jun 28, 2025

Walkthrough

A new documentation file for integrating Better Auth with ZenStack was added. Additionally, the sidebar position metadata in several authentication documentation files was updated to adjust their order in the sidebar. No functional or content changes were made to the existing documents except for the addition of the Better Auth guide.

Changes

File(s) Change Summary
docs/quick-start/authentication/better-auth.md Added new documentation for integrating Better Auth with ZenStack, including setup, usage, and policy examples.
docs/quick-start/authentication/auth0.md
docs/quick-start/authentication/clerk.md
docs/quick-start/authentication/lucia.md
docs/quick-start/authentication/supabase.md
Updated only the sidebar_position metadata in the frontmatter to adjust sidebar ordering.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant BetterAuth
    participant Server (Next.js)
    participant ZenStack

    User->>BetterAuth: Authenticate
    BetterAuth-->>Server (Next.js): Provide session (user, org, role)
    Server (Next.js)->>ZenStack: Pass user/org info to enhance()
    ZenStack-->>Server (Next.js): Enhanced Prisma client with access policies
    Server (Next.js)-->>User: Serve data with enforced policies
Loading

Possibly related PRs

  • zenstackhq/zenstack-docs#409: Adds a detailed blog guide on Better Auth multi-tenancy with ZenStack, directly related to the new Better Auth documentation.
  • zenstackhq/zenstack-docs#325: Modifies lucia.md content, related as both PRs affect the same file but with different types of changes.
  • zenstackhq/zenstack-docs#403: Updates auth0.md content, related by modifying the same file as this PR’s sidebar metadata update.

Suggested reviewers

  • ymc9

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

‼️ IMPORTANT
Auto-reply has been disabled for this repository in the CodeRabbit settings. The CodeRabbit bot will not respond to your replies unless it is explicitly tagged.

  • 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 explain this code block.
    • @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 explain its main purpose.
    • @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.

Support

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

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.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @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.

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 (4)
docs/quick-start/authentication/better-auth.md (4)

38-38: Add missing article “the” before api object

- Better Auth exposes that through `api` object of the `auth` instance.
+ Better Auth exposes that through the `api` object of the `auth` instance.

65-65: Insert “that” after “plugin system” for grammar

- Better Auth has a powerful plugin system allows you to add new features
+ Better Auth has a powerful plugin system that allows you to add new features

81-81: Fix typo “identiy” → “identity”

- // user identiy with organization info
+ // user identity with organization info

93-93: Clarify wording around enhanced client

The phrase “enhanced client” may confuse readers because the function is enhance(). Consider:

- Then you could pass this whole user context info to the `enhanced` client:
+ Then you can pass the full user-context object to an enhanced Prisma client created via `enhance()`:
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between f2b6059 and 0180380.

📒 Files selected for processing (5)
  • docs/quick-start/authentication/auth0.md (1 hunks)
  • docs/quick-start/authentication/better-auth.md (1 hunks)
  • docs/quick-start/authentication/clerk.md (1 hunks)
  • docs/quick-start/authentication/lucia.md (1 hunks)
  • docs/quick-start/authentication/supabase.md (1 hunks)
🧰 Additional context used
🪛 LanguageTool
docs/quick-start/authentication/better-auth.md

[uncategorized] ~38-~38: You might be missing the article “the” here.
Context: ...side, Better Auth exposes that through api object of the auth instance. For...

(AI_EN_LECTOR_MISSING_DETERMINER_THE)


[uncategorized] ~65-~65: A determiner appears to be missing. Consider inserting it.
Context: ...etter Auth has a powerful plugin system allows you to add new features that contribute...

(AI_EN_LECTOR_MISSING_DETERMINER)


[style] ~99-~99: Replace ‘get’ with a more descriptive word to set your writing apart from others.
Context: ...s via the special auth() function. To get it to work, let's add a type in ZModel to def...

(GET_STYLISH)


[grammar] ~129-~129: It appears that a hyphen is missing in the noun “To-do” (= task) or did you mean the verb “to do”?
Context: ...ind a complete sample of a multi-tenant Todo app code [here](https://github.com/ymc9...

(TO_DO_HYPHEN)

🔇 Additional comments (4)
docs/quick-start/authentication/clerk.md (1)

3-3: Sidebar reorder looks good

sidebar_position was bumped to 3, keeping the numeric sequence unique after inserting Better Auth at position 2. No further action required.

docs/quick-start/authentication/auth0.md (1)

3-3: Sidebar metadata updated correctly

Position updated to 5; ordering remains consistent with the rest of the authentication guides.

docs/quick-start/authentication/supabase.md (1)

3-3: Sidebar metadata updated correctly

sidebar_position: 4 fits the new ordering. No other changes detected.

docs/quick-start/authentication/lucia.md (1)

3-3: Sidebar metadata updated correctly

Value changed to 6; ordering stays unique and ascending.

@jiashengguo
Copy link
Member Author

@coderabbitai resolve

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jun 28, 2025

✅ Actions performed

Comments resolved.

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

🧹 Nitpick comments (2)
docs/quick-start/authentication/better-auth.md (2)

90-91: Split the run-on sentence for clarity

-The Better Auth CLI will only update the `schema.prisma` file, if you add the Organization plugin after installing the ZenStack, you need to copy the change to `schema.zmodel` too. 
+The Better Auth CLI updates only the `schema.prisma` file.  
+If you add the Organization plugin after installing ZenStack, remember to copy the generated changes to `schema.zmodel` as well.

99-100: Use a more descriptive verb than “get” and tighten wording

-The user context will be accessible in ZModel policy rules via the special `auth()` function. To get it to work, let's add a type in ZModel to define the shape of `auth()`:
+The user context becomes accessible in ZModel policy rules through the special `auth()` function. To enable this, add a type in ZModel that defines the shape of `auth()`:
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 0180380 and b09225e.

📒 Files selected for processing (1)
  • docs/quick-start/authentication/better-auth.md (1 hunks)
🧰 Additional context used
🪛 LanguageTool
docs/quick-start/authentication/better-auth.md

[style] ~99-~99: Replace ‘get’ with a more descriptive word to set your writing apart from others.
Context: ...s via the special auth() function. To get it to work, let's add a type in ZModel to def...

(GET_STYLISH)


[grammar] ~129-~129: It appears that a hyphen is missing in the noun “To-do” (= task) or did you mean the verb “to do”?
Context: ...ind a complete sample of a multi-tenant Todo app code [here](https://github.com/ymc9...

(TO_DO_HYPHEN)

🔇 Additional comments (1)
docs/quick-start/authentication/better-auth.md (1)

113-118: Confirm that Cascade is supported in ZModel

onDelete: Cascade is Prisma syntax. In ZModel, the cascade behaviour is implied by the Prisma layer, but the keyword itself is not recognised. Double-check that this annotation compiles with the latest ZenStack generator; if not, drop the onDelete argument and document the limitation.

Comment on lines +70 to +79

let organizationRole: string | undefined = undefined;
const organizationId = session.activeOrganizationId;
const org = await auth.api.getFullOrganization({ headers: reqHeaders });
if (org?.members) {
const myMember = org.members.find(
(m) => m.userId === session.userId
);
organizationRole = myMember?.role;
}
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

reqHeaders is undefined – align this snippet with the previous one

reqHeaders hasn’t been introduced anywhere, which will confuse readers. Either reuse headers() from the earlier example or show how reqHeaders is derived.

-const org = await auth.api.getFullOrganization({ headers: reqHeaders });
+const org = await auth.api.getFullOrganization({
+    headers: headers(), // reuse Next.js request headers
+});
📝 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
let organizationRole: string | undefined = undefined;
const organizationId = session.activeOrganizationId;
const org = await auth.api.getFullOrganization({ headers: reqHeaders });
if (org?.members) {
const myMember = org.members.find(
(m) => m.userId === session.userId
);
organizationRole = myMember?.role;
}
let organizationRole: string | undefined = undefined;
const organizationId = session.activeOrganizationId;
const org = await auth.api.getFullOrganization({
headers: headers(), // reuse Next.js request headers
});
if (org?.members) {
const myMember = org.members.find(
(m) => m.userId === session.userId
);
organizationRole = myMember?.role;
}
🤖 Prompt for AI Agents
In docs/quick-start/authentication/better-auth.md around lines 70 to 79, the
variable reqHeaders is used but never defined, causing confusion. Fix this by
either replacing reqHeaders with headers() as used in the previous snippet or
explicitly define reqHeaders before this code block to show how it is derived,
ensuring consistency and clarity for readers.

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
@jiashengguo jiashengguo merged commit bcc2118 into main Jun 28, 2025
4 checks passed
@jiashengguo jiashengguo deleted the jiasheng branch June 28, 2025 09:14
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.

2 participants