Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions app/auth/callback/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,12 @@ function OAuthCallbackContent() {
try {
await profileService.getProfile(session.user.id);
console.log('Profile created via profileService, redirecting to complete profile');
router.replace('/complete-profile');
router.replace(`/complete-profile?returnUrl=${encodeURIComponent(returnUrl)}`);
return;
} catch (profileError) {
console.error('Error creating profile:', profileError);
// Continue to complete profile page anyway
router.replace('/complete-profile');
router.replace(`/complete-profile?returnUrl=${encodeURIComponent(returnUrl)}`);
return;
}
}
Expand Down Expand Up @@ -119,12 +119,12 @@ function OAuthCallbackContent() {
try {
await profileService.getProfile(retrySession.user.id);
console.log('Profile created via profileService on retry, redirecting to complete profile');
router.replace('/complete-profile');
router.replace(`/complete-profile?returnUrl=${encodeURIComponent(returnUrl)}`);
return;
} catch (profileError) {
console.error('Error creating profile on retry:', profileError);
// Continue to complete profile page anyway
router.replace('/complete-profile');
router.replace(`/complete-profile?returnUrl=${encodeURIComponent(returnUrl)}`);
return;
}
}
Expand All @@ -137,13 +137,13 @@ function OAuthCallbackContent() {

if (!isProfileComplete) {
console.log('Profile incomplete on retry, redirecting to complete profile');
router.replace('/complete-profile');
router.replace(`/complete-profile?returnUrl=${encodeURIComponent(returnUrl)}`);
return;
}
} catch (profileError) {
console.error('Error checking profile for OAuth user on retry:', profileError);
// If there's an error, redirect to complete profile to be safe
router.replace('/complete-profile');
router.replace(`/complete-profile?returnUrl=${encodeURIComponent(returnUrl)}`);
return;
}

Expand All @@ -170,12 +170,12 @@ function OAuthCallbackContent() {
try {
await profileService.getProfile(finalSession.user.id);
console.log('Profile created via profileService on final try, redirecting to complete profile');
router.replace('/complete-profile');
router.replace(`/complete-profile?returnUrl=${encodeURIComponent(returnUrl)}`);
return;
} catch (profileError) {
console.error('Error creating profile on final try:', profileError);
// Continue to complete profile page anyway
router.replace('/complete-profile');
router.replace(`/complete-profile?returnUrl=${encodeURIComponent(returnUrl)}`);
return;
}
}
Expand All @@ -188,13 +188,13 @@ function OAuthCallbackContent() {

if (!isProfileComplete) {
console.log('Profile incomplete on final try, redirecting to complete profile');
router.replace('/complete-profile');
router.replace(`/complete-profile?returnUrl=${encodeURIComponent(returnUrl)}`);
return;
}
} catch (profileError) {
console.error('Error checking profile for OAuth user on final try:', profileError);
// If there's an error, redirect to complete profile to be safe
router.replace('/complete-profile');
router.replace(`/complete-profile?returnUrl=${encodeURIComponent(returnUrl)}`);
return;
}

Expand Down
11 changes: 7 additions & 4 deletions app/complete-profile/page.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use client';

import { useState, useEffect, useCallback, useRef } from 'react';
import { useRouter } from 'next/navigation';
import { useRouter, useSearchParams } from 'next/navigation';
import Link from 'next/link';
import { createClient } from '@/lib/supabase/client';
import { toast } from 'sonner';
Expand All @@ -23,6 +23,10 @@ interface User {
}

export default function CompleteProfile() {
const router = useRouter();
const searchParams = useSearchParams();
const returnUrl = searchParams.get('returnUrl') || '/protected/dashboard';

const [firstName, setFirstName] = useState('');
const [lastName, setLastName] = useState('');
const [username, setUsername] = useState('');
Expand All @@ -32,7 +36,6 @@ export default function CompleteProfile() {
const [usernameError, setUsernameError] = useState<string>('');
const [user, setUser] = useState<User | null>(null);
const [isValidating, setIsValidating] = useState(true);
const router = useRouter();
const usernameCheckTimeout = useRef<ReturnType<typeof setTimeout> | null>(null);

const getSupabaseClient = () => {
Expand Down Expand Up @@ -60,7 +63,7 @@ export default function CompleteProfile() {

if (isProfileComplete) {
// Profile is already complete, redirect to dashboard
router.push('/protected/dashboard');
router.push(returnUrl);
return;
}

Expand Down Expand Up @@ -223,7 +226,7 @@ export default function CompleteProfile() {
}

toast.success('Profile completed successfully! Welcome to CodeUnia! 🎉');
router.push('/protected/dashboard');
router.push(returnUrl);
} catch (error) {
console.error('Error updating profile:', error);
toast.error('Error completing profile setup');
Expand Down
Loading