11'use client' ;
2- import { useEffect , useState } from 'react' ;
2+ import { useEffect , useRef , useState } from 'react' ;
33import { useRouter , useSearchParams } from 'next/navigation' ;
44import { useAuthContext } from '@/providers/AuthProvider' ;
55import { Card , CardContent , CardDescription , CardFooter , CardHeader , CardTitle } from '@/components/ui/card' ;
@@ -14,8 +14,12 @@ export default function GitHubCallback() {
1414
1515 const [ status , setStatus ] = useState < 'loading' | 'success' | 'error' > ( 'loading' ) ;
1616 const [ errorMessage , setErrorMessage ] = useState < string | null > ( null ) ;
17+
18+ const hasCalledBackend = useRef ( false ) ; // Add guard flag here
1719
1820 useEffect ( ( ) => {
21+ if ( hasCalledBackend . current ) return ; // Prevent multiple calls
22+
1923 // Extract installation ID from search params
2024 const githubCode = searchParams . get ( 'code' ) ;
2125 const installationId = searchParams . get ( 'installation_id' ) ;
@@ -43,6 +47,8 @@ export default function GitHubCallback() {
4347 setErrorMessage ( 'No installation ID was provided.' ) ;
4448 return ;
4549 }
50+
51+ hasCalledBackend . current = true ;
4652
4753 // Call the backend directly to store the installation ID
4854 const storeInstallation = async ( ) => {
@@ -82,7 +88,7 @@ export default function GitHubCallback() {
8288
8389 // Function to handle redirect back to projects
8490 const handleContinue = ( ) => {
85- router . push ( '/projects ' ) ; // Change this to your desired redirect path
91+ router . push ( '/' ) ; // Change this to your desired redirect path
8692 } ;
8793
8894 return (
0 commit comments