-
-
Notifications
You must be signed in to change notification settings - Fork 38
doc: add better Auth integration #468
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
Conversation
|
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
WalkthroughA 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
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
Possibly related PRs
Suggested reviewers
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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed 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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
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.
Actionable comments posted: 0
🧹 Nitpick comments (4)
docs/quick-start/authentication/better-auth.md (4)
38-38: Add missing article “the” beforeapiobject- 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 clientThe phrase “
enhancedclient” may confuse readers because the function isenhance(). 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
📒 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_positionwas bumped to3, 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 correctlyPosition 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: 4fits the new ordering. No other changes detected.docs/quick-start/authentication/lucia.md (1)
3-3: Sidebar metadata updated correctlyValue changed to
6; ordering stays unique and ascending.
|
@coderabbitai resolve |
✅ Actions performedComments resolved. |
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.
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
📒 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 thatCascadeis supported in ZModel
onDelete: Cascadeis 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 theonDeleteargument and document the limitation.
|
|
||
| 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; | ||
| } |
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.
🛠️ 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.
| 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>
This reverts commit af26de9.
Summary by CodeRabbit
New Features
Documentation