🛂 server: add better auth is an authentication framework#881
🛂 server: add better auth is an authentication framework#881nfmelendez wants to merge 4 commits intomainfrom
Conversation
🦋 Changeset detectedLatest commit: 80fc2a3 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request introduces a robust authentication and authorization system by integrating the 'better-auth' framework. It enables advanced features such as Sign-In with Ethereum (SIWE) and comprehensive organization management, allowing users to create organizations and manage members with distinct roles. The changes span across database schema, API endpoints, middleware, and user-facing documentation, laying the groundwork for secure and scalable user and organization interactions. Highlights
Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
|
Warning Rate limit exceeded
Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 59 minutes and 45 seconds. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Pro Run ID: ⛔ Files ignored due to path filters (1)
📒 Files selected for processing (15)
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
WalkthroughAdds BetterAuth-based SIWE authentication and organization support: new Drizzle Postgres schema and relations, exported database and authAdapter, BetterAuth configuration and routes, middleware session fallback, OpenAPI security entry, docs, and three changeset files. Changes
Sequence Diagram(s)sequenceDiagram
participant Client as Client (Browser)
participant Auth as BetterAuth Handler
participant Server as App Server
participant DB as Database
participant Sentry as Sentry
Client->>Auth: GET /api/auth/nonce
Auth->>DB: store nonce
DB-->>Auth: nonce
Auth-->>Client: nonce
Client->>Client: sign SIWE message
Client->>Auth: POST /api/auth/verify (signed message)
Auth->>Auth: parse & verify chainId/address/signature
alt valid
Auth->>DB: create/update user & session
DB-->>Auth: session
Auth->>Server: set __Secure-better-auth.session_token
Server-->>Client: success response
else invalid
Auth->>Sentry: capture verification error
Sentry-->>Auth: ack
Auth-->>Client: unauthorized
end
Client->>Server: POST /api/auth/create-organization (with session)
Server->>DB: create organization & member
DB-->>Server: organization created
Server-->>Client: organization id/details
Estimated code review effort🎯 4 (Complex) | ⏱️ ~60 minutes Possibly related PRs
Suggested reviewers
🚥 Pre-merge checks | ✅ 2✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #881 +/- ##
==========================================
- Coverage 71.74% 71.65% -0.09%
==========================================
Files 229 231 +2
Lines 8292 8344 +52
Branches 2669 2673 +4
==========================================
+ Hits 5949 5979 +30
- Misses 2113 2135 +22
Partials 230 230
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Actionable comments posted: 12
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: ASSERTIVE
Plan: Pro
Run ID: ac66a631-8798-4e64-80e3-76561a0be138
⛔ Files ignored due to path filters (1)
pnpm-lock.yamlis excluded by!**/pnpm-lock.yaml
📒 Files selected for processing (12)
.changeset/cool-snakes-reply.md.changeset/pretty-chicken-hang.md.changeset/rare-pears-sort.mddocs/astro.config.tsdocs/src/content/docs/organization-authentication.mdserver/database/index.tsserver/database/schema.tsserver/index.tsserver/middleware/auth.tsserver/package.jsonserver/script/openapi.tsserver/utils/auth.ts
c2defde to
c93fb20
Compare
6d12264 to
811d11f
Compare
There was a problem hiding this comment.
♻️ Duplicate comments (1)
server/middleware/auth.ts (1)
10-19:⚠️ Potential issue | 🔴 CriticalType signature doesn't match runtime behavior—when BetterAuth session is used,
credentialIdis undefined, not the string promised by the middleware type.The middleware declares
{ out: { cookie: { credentialId: string } } }, but the BetterAuth fallback path (lines 14–17) callsnext()without settingcredentialId. All nine endpoints usingauth()destructure{ credentialId }and will receiveundefinedwhen a BetterAuth session is used.Per the design intent (noted in prior review), this fallback is for endpoints that don't require
credentialId. However, every current endpoint usingauth()does require it. Either:
- Make the type accurate:
{ credentialId?: string }and add conditional logic in endpoints to handle both auth methods- Separate concerns: create distinct middleware for credential-based vs session-based authentication
- Confirm whether the BetterAuth path is intended to be unreachable for these endpoints
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: ASSERTIVE
Plan: Pro
Run ID: 8c01d4f7-1f82-4e51-b6b8-fe3ea4aeb76a
📒 Files selected for processing (8)
.changeset/rare-pears-sort.mddocs/astro.config.tsdocs/src/content/docs/organization-authentication.mdserver/database/index.tsserver/index.tsserver/middleware/auth.tsserver/script/openapi.tsserver/utils/auth.ts
72065d0 to
128b4ec
Compare
|
@CodeRabbit review |
✅ Actions performedReview triggered.
|
Summary by CodeRabbit
New Features
Documentation
Chores
Security