-
-
Notifications
You must be signed in to change notification settings - Fork 38
doc: guide for custom auth #395
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 ↗︎
|
WalkthroughThis pull request introduces a new documentation file, Changes
Possibly related PRs
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? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
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: 1
🧹 Outside diff range and nitpick comments (5)
docs/guides/authentication/custom.md (5)
37-37: Fix typo in explanationChange "any thing" to "anything" for better grammar.
-Just remember that any thing that you access from `auth().` must be resolved. +Just remember that anything that you access from `auth().` must be resolved.
18-24: Add explanatory comments to code examplesConsider adding comments to explain the purpose of each field in the models.
model User { + // Unique identifier for the user id String @id + // User's role for RBAC role String + // Array of fine-grained permissions permissions String[] ... } type Auth { + // Unique identifier for the user (matches JWT or external auth system) id String @id + // User's role for access control role String + // List of specific permissions assigned to the user permissions String[] @@auth }Also applies to: 29-35
41-46: Enhance the runtime implementation sectionConsider the following improvements:
- Add concrete code examples for JWT token validation and authentication service integration
- Make the security warning more prominent, possibly in a dedicated "Security Considerations" section
Example additions:
// JWT token example import jwt from 'jsonwebtoken'; async function getCurrentUser(token: string) { try { // Verify and decode the JWT token const decoded = jwt.verify(token, process.env.JWT_SECRET); return { id: decoded.sub, role: decoded.role, permissions: decoded.permissions }; } catch (error) { throw new Error('Invalid or expired token'); } } // Authentication service example async function getCurrentUser(sessionId: string) { const response = await authService.validateSession(sessionId); if (!response.valid) { throw new Error('Invalid session'); } return { id: response.userId, role: response.userRole, permissions: response.permissions }; }
52-55: Enhance the client example with error handling and typesThe example could be improved with proper error handling and TypeScript types.
```ts -const user = await getCurrentUser(); // your implementation -const db = enhance(prisma, { user }); +interface AuthUser { + id: string; + role: string; + permissions: string[]; +} + +try { + const user: AuthUser = await getCurrentUser(); // your implementation + const db = enhance(prisma, { + user, + onError: (error) => { + console.error('Access policy violation:', error); + // Handle error appropriately + } + }); +} catch (error) { + // Handle authentication errors + console.error('Failed to get current user:', error); +}--- `55-55`: **Consider adding important missing sections** The guide would benefit from additional sections: 1. Testing Access Policies - How to write tests for custom authentication - Examples of mocking the auth context 2. Troubleshooting - Common issues and solutions - Debugging access policy violations Would you like me to help draft these additional sections? </blockquote></details> </blockquote></details> <details> <summary>📜 Review details</summary> **Configuration used: CodeRabbit UI** **Review profile: CHILL** <details> <summary>📥 Commits</summary> Reviewing files that changed from the base of the PR and between 450eb4c094d6364eae456a4477614840f7730991 and 6d46b546c3b5e459d91894b7991099abe57a24f4. </details> <details> <summary>📒 Files selected for processing (1)</summary> * `docs/guides/authentication/custom.md` (1 hunks) </details> </details> <!-- This is an auto-generated comment by CodeRabbit for review status -->
| --- | ||
| description: Integrating with a custom authentication system. | ||
| sidebar_position: 100 | ||
| sidebar_label: Custom Authentication | ||
| --- |
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.
💡 Codebase verification
Sidebar position should be adjusted to maintain documentation order
The high sidebar_position: 100 appears to be inconsistent with the sequence of other authentication guides which use values 1-6. Since this is a custom authentication guide, it should be positioned appropriately within the sequence, likely after the specific auth provider guides.
- Consider adjusting
sidebar_positionto7to maintain a logical sequence after auth0 (6) and other specific providers - Current sequence: next-auth (1), clerk (2), supabase (3), lucia (5), auth0 (6), custom (100)
🔗 Analysis chain
Verify the sidebar position value
The sidebar_position: 100 seems unusually high. Please confirm if this is intentional or if it should be adjusted to match the sequence of other authentication guides.
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Check other authentication guide positions
fd -e md . docs/guides/authentication -x grep -l "sidebar_position" {} \; | xargs grep "sidebar_position"
Length of output: 452
Summary by CodeRabbit
custom.mdcreated with detailed instructions and examples for users.