Skip to content

Conversation

@Leon-JavaScript
Copy link
Member

This PR moves the authentication check and redirect logic from the individual LoginPage and SignupPage components into the shared AuthLayout component.

Changes

  • AuthLayout:
    • Added a useEffect hook to check if the user is already authenticated via /api/users/me.
    • If authenticated, automatically redirects to /projects.
  • LoginPage & SignupPage:
    • Removed redundant authentication checks and redirects, as these are now handled by the layout.

@Leon-JavaScript Leon-JavaScript added this to the v1.0.2 milestone Jan 10, 2026
@Leon-JavaScript Leon-JavaScript self-assigned this Jan 10, 2026
@Leon-JavaScript Leon-JavaScript added the Priority: Medium Should be done for the next regular version label Jan 10, 2026
Copy link

Copilot AI left a 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.

Comment on lines +17 to +34
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]);
Copy link

Copilot AI Jan 10, 2026

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.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Priority: Medium Should be done for the next regular version

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants