-
-
Notifications
You must be signed in to change notification settings - Fork 393
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
🐛 Handle missing session #1456
🐛 Handle missing session #1456
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
1 Skipped Deployment
|
WalkthroughThe changes involve the addition of a session validation mechanism in the Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant App
participant Session
User->>App: Access Application
App->>Session: Check Session
alt Session is valid
Session-->>App: Session exists
App-->>User: Render Main Layout
else Session is invalid
Session-->>App: No session
App-->>User: Redirect to /login
end
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: 0
🧹 Outside diff range and nitpick comments (2)
apps/web/src/app/[locale]/layout.tsx (2)
36-38
: Consider enhancing the session handling implementation.While the basic session validation works, consider these improvements for a more robust implementation:
- Store the current URL when redirecting to login to enable redirect-back functionality
- Use environment variables for the login path instead of hardcoding
- Consider adding support for public routes that don't require authentication
Here's a suggested implementation:
+ const currentPath = headers().get("x-url") || ""; + const isPublicRoute = ["/login", "/register"].includes(currentPath); - if (!session) { - redirect("/login"); - } + if (!session && !isPublicRoute) { + const loginUrl = process.env.NEXT_PUBLIC_LOGIN_PATH || "/login"; + const searchParams = new URLSearchParams({ + callbackUrl: currentPath, + }); + redirect(`${loginUrl}?${searchParams.toString()}`); + }
35-39
: Strong security implementation at the layout level.Implementing the session check in the root layout provides comprehensive protection for all child routes. This is a secure approach as it:
- Prevents unauthorized access to protected routes
- Ensures consistent authentication checks across the application
- Handles session validation before any rendering occurs
Consider documenting this security boundary in your architecture documentation to make it clear that all routes under this layout inherit authentication protection.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (1)
apps/web/src/app/[locale]/layout.tsx
(2 hunks)
🔇 Additional comments (1)
apps/web/src/app/[locale]/layout.tsx (1)
7-7
: LGTM! Correct usage of Next.js redirect.
The import of redirect
from next/navigation
follows Next.js best practices for handling redirects in server components.
Summary by CodeRabbit
New Features
Bug Fixes