Skip to content

Commit 6211465

Browse files
committed
fix: resolve authentication flow issues and eliminate no_session errors - remove client-side OAuth callback pages to prevent conflicts - enhance middleware with grace periods for signup/OAuth flows - add from=signup parameter to dashboard redirects - improve session establishment timing and retry logic - add success message handling in login component - resolves redirect issues after signup in production
1 parent 2330213 commit 6211465

File tree

16 files changed

+484
-528
lines changed

16 files changed

+484
-528
lines changed

.coderabbit.yaml

Lines changed: 39 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -12,49 +12,49 @@ frameworks:
1212
reviews:
1313
# Enable automatic reviews on pull requests
1414
auto_review: true
15-
15+
1616
# Enable draft PR reviews
1717
draft_reviews: true
18-
18+
1919
# Review scope
2020
scope:
21-
- "src/**"
22-
- "*.ts"
23-
- "*.tsx"
24-
- "*.js"
25-
- "*.jsx"
26-
- "*.json"
27-
- "*.md"
28-
- ".github/**"
29-
21+
- 'src/**'
22+
- '*.ts'
23+
- '*.tsx'
24+
- '*.js'
25+
- '*.jsx'
26+
- '*.json'
27+
- '*.md'
28+
- '.github/**'
29+
3030
# Exclude patterns
3131
exclude:
32-
- "node_modules/**"
33-
- ".next/**"
34-
- "dist/**"
35-
- "build/**"
36-
- "coverage/**"
37-
- "*.min.js"
38-
- "yarn.lock"
39-
- "package-lock.json"
32+
- 'node_modules/**'
33+
- '.next/**'
34+
- 'dist/**'
35+
- 'build/**'
36+
- 'coverage/**'
37+
- '*.min.js'
38+
- 'yarn.lock'
39+
- 'package-lock.json'
4040

4141
# Code quality checks
4242
quality:
4343
# Security checks
4444
security: true
45-
45+
4646
# Performance analysis
4747
performance: true
48-
48+
4949
# Best practices
5050
best_practices: true
51-
51+
5252
# Code style and formatting
5353
style: true
54-
54+
5555
# Type safety (TypeScript)
5656
type_safety: true
57-
57+
5858
# Test coverage analysis
5959
test_coverage: true
6060

@@ -66,21 +66,21 @@ rules:
6666
- use_proper_hooks_dependencies
6767
- avoid_inline_styles
6868
- proper_key_props
69-
69+
7070
# TypeScript specific
7171
typescript:
7272
- strict_type_checking
7373
- no_any_types
7474
- proper_interface_naming
7575
- consistent_return_types
76-
76+
7777
# Security specific
7878
security:
7979
- no_hardcoded_secrets
8080
- secure_api_endpoints
8181
- proper_authentication_checks
8282
- validate_user_inputs
83-
83+
8484
# Performance specific
8585
performance:
8686
- optimize_database_queries
@@ -93,33 +93,33 @@ integrations:
9393
github:
9494
# Enable PR comments
9595
pr_comments: true
96-
96+
9797
# Enable status checks
9898
status_checks: true
99-
99+
100100
# Auto-approve minor changes (optional)
101101
auto_approve_minor: false
102-
102+
103103
# Request reviews for major changes
104104
request_human_review: true
105105

106106
# Notification settings
107107
notifications:
108108
# Notify on high-priority issues
109109
high_priority: true
110-
110+
111111
# Notify on security issues
112112
security_issues: true
113-
113+
114114
# Summary reports
115115
summary_reports: true
116116

117117
# Custom prompts for this project
118118
custom_prompts:
119-
- "Focus on real-time collaboration features and ensure proper handling of concurrent users"
120-
- "Pay attention to Supabase integration and PostgREST query optimization"
121-
- "Review authentication and authorization implementation carefully"
122-
- "Check for proper error handling in async operations"
123-
- "Ensure proper cleanup of real-time subscriptions and connections"
124-
- "Validate proper use of React hooks and state management"
125-
- "Review test coverage and quality of unit tests"
119+
- 'Focus on real-time collaboration features and ensure proper handling of concurrent users'
120+
- 'Pay attention to Supabase integration and PostgREST query optimization'
121+
- 'Review authentication and authorization implementation carefully'
122+
- 'Check for proper error handling in async operations'
123+
- 'Ensure proper cleanup of real-time subscriptions and connections'
124+
- 'Validate proper use of React hooks and state management'
125+
- 'Review test coverage and quality of unit tests'

README.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,6 @@
8787

8888
### 📝 Real-time Editor
8989

90-
9190
![dashboard](/public/project-images/realtime-dashboard.png)
9291
![Real-time Editor](public/project-images/3.png)
9392
![Collaboration](public/project-images/13.png)
@@ -332,35 +331,41 @@ src/
332331
### v2.0.0 - PostgREST Migration & Enhanced Collaboration
333332

334333
#### 🔄 Database Layer Refactor
334+
335335
- **Migrated from Drizzle ORM to PostgREST**: Improved performance and simplified database interactions
336336
- **Enhanced Query Optimization**: More efficient data fetching with PostgREST's built-in filtering and pagination
337337
- **Type Safety**: Maintained full TypeScript support throughout the migration
338338

339339
#### 👥 Improved Collaborator System
340+
340341
- **Complete Collaborator Visibility**: All workspace members (owners and invitees) can now see the full collaborator list
341342
- **Online Status Indicators**: Real-time green dots show who's currently active
342343
- **Avatar Fallbacks**: Proper avatar fallbacks for all collaborators
343344
- **Enhanced Tooltips**: Detailed collaborator information with online status
344345

345346
#### 🎨 UI/UX Enhancements
347+
346348
- **Breadcrumb Navigation**: Instant visibility of workspace/folder/file names
347349
- **Banner Inheritance**: Folders and files inherit workspace banners when not set
348350
- **Connection Status**: Real-time connection indicators
349351
- **Responsive Collaborator List**: Better mobile experience for collaboration features
350352

351353
#### 🚀 Performance Optimizations
354+
352355
- **Reduced Re-rendering**: Optimized React hooks and memoization
353356
- **Stable Realtime Connections**: Improved WebSocket connection management
354357
- **Memory Leak Prevention**: Proper cleanup of realtime subscriptions
355358
- **Concurrent Connection Limits**: Reduced Supabase realtime connection usage
356359

357360
#### 🔧 Developer Experience
361+
358362
- **Linting Improvements**: Fixed all ESLint warnings and errors
359363
- **Build Optimization**: Resolved TypeScript compilation issues
360364
- **Code Organization**: Better separation of concerns and cleaner architecture
361365
- **Error Handling**: Enhanced error boundaries and user feedback
362366

363367
#### 🐛 Bug Fixes
368+
364369
- **Redirect Loop Fix**: Resolved dashboard navigation issues
365370
- **Stripe Integration**: Fixed deprecated payment session properties
366371
- **Authentication Flow**: Improved server-side authentication handling

src/app/(auth)/auth/callback/page.tsx

Lines changed: 0 additions & 28 deletions
This file was deleted.

src/app/(auth)/callback/page.tsx

Lines changed: 0 additions & 46 deletions
This file was deleted.

src/app/(site)/__tests__/page.test.tsx

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@ vi.mock('@/components/features/landing-page', () => ({
77
default: () => (
88
<div data-testid="landing-page">
99
<h1>Real-time Collaborative Platform</h1>
10-
<p>Welcome to the real-time collaborative platform. Boost productivity and teamwork with seamless collaboration tools.</p>
10+
<p>
11+
Welcome to the real-time collaborative platform. Boost productivity and teamwork with
12+
seamless collaboration tools.
13+
</p>
1114
<section>
1215
<h2>Features</h2>
1316
<ul>
@@ -33,26 +36,26 @@ vi.mock('@/lib/utils/sync-stripe-products', () => ({
3336
describe('HomePage Component', () => {
3437
it('renders the home page with correct metadata', () => {
3538
render(<HomePage />);
36-
39+
3740
// Check that the landing page component is rendered
3841
expect(screen.getByTestId('landing-page')).toBeInTheDocument();
3942
});
4043

4144
it('displays the main heading', () => {
4245
render(<HomePage />);
43-
46+
4447
expect(screen.getByText('Real-time Collaborative Platform')).toBeInTheDocument();
4548
});
4649

4750
it('shows the welcome description', () => {
4851
render(<HomePage />);
49-
52+
5053
expect(screen.getByText(/Welcome to the real-time collaborative platform/)).toBeInTheDocument();
5154
});
5255

5356
it('displays features section', () => {
5457
render(<HomePage />);
55-
58+
5659
expect(screen.getByText('Features')).toBeInTheDocument();
5760
expect(screen.getByText('Real-time editing')).toBeInTheDocument();
5861
expect(screen.getByText('Collaborative workspaces')).toBeInTheDocument();
@@ -61,7 +64,7 @@ describe('HomePage Component', () => {
6164

6265
it('shows get started section with action buttons', () => {
6366
render(<HomePage />);
64-
67+
6568
expect(screen.getByText('Get Started')).toBeInTheDocument();
6669
expect(screen.getByRole('button', { name: 'Sign Up' })).toBeInTheDocument();
6770
expect(screen.getByRole('button', { name: 'Learn More' })).toBeInTheDocument();

src/app/api/auth/callback/route.ts

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,19 +27,43 @@ export async function POST(request: NextRequest) {
2727
success: !exchangeError,
2828
error: exchangeError?.message,
2929
user: data?.user ? 'present' : 'missing',
30+
session: data?.session ? 'present' : 'missing',
3031
});
3132

3233
if (exchangeError) {
3334
console.error('Code exchange error:', exchangeError);
3435
return NextResponse.redirect(new URL('/login?error=auth_failed', request.url));
3536
}
3637

37-
if (data?.user) {
38+
if (data?.user && data?.session) {
3839
console.log('Auth callback - Successfully authenticated user:', data.user.email);
39-
// Successful authentication
40-
return NextResponse.redirect(new URL('/dashboard', request.url));
40+
console.log('Auth callback - Session established, redirecting to dashboard');
41+
42+
// Set cookies and redirect to dashboard
43+
const response = NextResponse.redirect(new URL('/dashboard?from=oauth', request.url));
44+
45+
// Ensure cookies are properly set for the session
46+
if (data.session.access_token) {
47+
response.cookies.set('sb-access-token', data.session.access_token, {
48+
httpOnly: true,
49+
secure: process.env.NODE_ENV === 'production',
50+
sameSite: 'lax',
51+
maxAge: 60 * 60 * 24 * 7, // 7 days
52+
});
53+
}
54+
55+
if (data.session.refresh_token) {
56+
response.cookies.set('sb-refresh-token', data.session.refresh_token, {
57+
httpOnly: true,
58+
secure: process.env.NODE_ENV === 'production',
59+
sameSite: 'lax',
60+
maxAge: 60 * 60 * 24 * 30, // 30 days
61+
});
62+
}
63+
64+
return response;
4165
} else {
42-
console.error('Auth callback - No user data after successful exchange');
66+
console.error('Auth callback - No user or session data after successful exchange');
4367
return NextResponse.redirect(new URL('/login?error=no_user_data', request.url));
4468
}
4569
}
@@ -57,5 +81,3 @@ export async function GET(request: NextRequest) {
5781
// Handle GET requests (for direct browser navigation)
5882
return POST(request);
5983
}
60-
61-

0 commit comments

Comments
 (0)