-
Notifications
You must be signed in to change notification settings - Fork 0
Centralize Auth Redirect Logic in AuthLayout Component #17
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
base: master
Are you sure you want to change the base?
Conversation
…cks from LoginPage and SignupPage
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.
Pull request overview
This PR centralizes authentication redirect logic by moving the authentication check from individual LoginPage and SignupPage components into the shared AuthLayout component. This eliminates code duplication and ensures consistent behavior across authentication pages.
Changes:
- Moved authentication check and redirect logic from LoginPage and SignupPage to AuthLayout
- AuthLayout now checks if users are authenticated on mount and redirects to /projects if they are
- Removed duplicate useEffect hooks from both login and signup pages
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| src/app/(auth)/layout.tsx | Added authentication check with useEffect hook that redirects authenticated users to /projects |
| src/app/(auth)/login/page.tsx | Removed duplicate authentication check logic now handled by layout |
| src/app/(auth)/signup/page.tsx | Removed duplicate authentication check logic now handled by layout |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| useEffect(() => { | ||
| async function checkAuth() { | ||
| try { | ||
| const response = await fetch('/api/users/me', { | ||
| credentials: 'include', | ||
| }); | ||
|
|
||
| if (response.ok) { | ||
| // User is already authenticated, redirect to projects | ||
| router.push('/projects'); | ||
| } | ||
| } catch { | ||
| // User is not authenticated, stay on auth page | ||
| } | ||
| } | ||
|
|
||
| checkAuth(); | ||
| }, [router]); |
Copilot
AI
Jan 10, 2026
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.
The authentication check in the layout should include a loading state to prevent flashing the login/signup form before redirecting authenticated users. The dashboard layout (in src/app/(dashboard)/layout.tsx) implements this pattern correctly with an isChecking state that shows a loading indicator. Without this, users may briefly see the auth form before being redirected to /projects.
This PR moves the authentication check and redirect logic from the individual LoginPage and SignupPage components into the shared AuthLayout component.
Changes