This repository has no description
0

Configure Feed

Select the types of activity you want to include in your feed.

another fix

+44 -6
+44 -6
src/components/Login/LoginCallback.js
··· 5 5 6 6 const LoginCallback = () => { 7 7 // Get loading and authentication status from AuthContext 8 - const { loading, isAuthenticated, error: authError } = useAuth(); 8 + const { loading, isAuthenticated, error: authError, session } = useAuth(); 9 9 const navigate = useNavigate(); 10 10 const location = useLocation(); 11 11 const [localError, setLocalError] = useState(null); 12 12 13 13 useEffect(() => { 14 + // Log location information for debugging 15 + console.log('(LoginCallback) Current location:', { 16 + pathname: location.pathname, 17 + search: location.search, 18 + hash: location.hash, 19 + state: location.state 20 + }); 21 + 14 22 // Don't do anything until the AuthProvider is done loading 15 23 if (loading) { 16 24 return; ··· 20 28 if (isAuthenticated) { 21 29 console.log('(LoginCallback) Authentication successful, redirecting...'); 22 30 23 - // Parse returnUrl from query parameters 31 + // First, try to get returnUrl from localStorage (set during login) 32 + let returnUrl = localStorage.getItem('auth_redirect_url'); 33 + console.log('(LoginCallback) Found returnUrl in localStorage:', returnUrl); 34 + 35 + // Parse returnUrl from query parameters (if present) 24 36 const searchParams = new URLSearchParams(location.search); 25 - const returnUrl = searchParams.get('returnUrl') || '/verifier'; 37 + if (searchParams.has('returnUrl')) { 38 + returnUrl = searchParams.get('returnUrl'); 39 + console.log(`(LoginCallback) Overriding with returnUrl from URL:`, returnUrl); 40 + } 26 41 27 - console.log(`(LoginCallback) Redirecting to: ${returnUrl}`); 28 - navigate(returnUrl, { replace: true }); // Use replace to avoid callback in history 42 + // Check if we have state data from the OAuth callback 43 + if (session?.state) { 44 + try { 45 + // The state is stored as a JSON string 46 + const stateData = JSON.parse(session.state); 47 + if (stateData && stateData.returnUrl) { 48 + console.log(`(LoginCallback) Found returnUrl in OAuth state:`, stateData.returnUrl); 49 + returnUrl = stateData.returnUrl; 50 + } 51 + } catch (err) { 52 + console.error('(LoginCallback) Error parsing state data:', err); 53 + } 54 + } 55 + 56 + // Fallback to /verifier if no returnUrl found 57 + if (!returnUrl) { 58 + returnUrl = '/verifier'; 59 + console.log(`(LoginCallback) No returnUrl found, defaulting to:`, returnUrl); 60 + } 61 + 62 + // Clean up localStorage 63 + localStorage.removeItem('auth_redirect_url'); 64 + 65 + console.log(`(LoginCallback) Final redirect destination:`, returnUrl); 66 + navigate(returnUrl, { replace: true }); 29 67 } else { 30 68 // If not authenticated after loading, something went wrong 31 69 console.error('(LoginCallback) Authentication failed after loading.'); 32 70 setLocalError(authError || 'Authentication failed. Please try logging in again.'); 33 71 } 34 72 35 - }, [loading, isAuthenticated, navigate, authError, location]); // Added location dependency 73 + }, [loading, isAuthenticated, navigate, authError, location, session]); // Added session dependency 36 74 37 75 // Display loading message 38 76 if (loading) {