@@ -5,32 +5,33 @@ import {HeroPattern} from "@/components/HeroPattern";
55import { Footer } from "@/components/Footer" ;
66import { useRouter , useSearchParams } from "next/navigation" ;
77import { useEffect , Suspense } from "react" ;
8- import { storeSessionFromString , getSession } from "@/utils/sessionUtils" ;
8+ import { storeSessionFromString , getSession , storeApiBaseURL } from "@/utils/sessionUtils" ;
99
1010// Separate the component that uses useSearchParams
1111function AuthHandler ( ) {
1212 const router = useRouter ( ) ;
1313 const searchParams = useSearchParams ( ) ;
14+ const apiBaseUrl = searchParams . get ( 'api_base_url' ) ;
1415 const session = searchParams . get ( 'session' ) ;
1516
1617 useEffect ( ( ) => {
18+ if ( apiBaseUrl ) {
19+ storeApiBaseURL ( apiBaseUrl ) ;
20+ }
1721 const handleAsync = async ( ) => {
1822 if ( session ) {
1923 try {
20- // Decode base64 session parameter
2124 const decodedSession = atob ( session ) ;
2225 storeSessionFromString ( decodedSession ) ;
2326 await router . push ( "/" ) ;
2427 } catch ( error ) {
2528 console . error ( 'Failed to decode session:' , error ) ;
2629 }
2730 } else {
28- // Check if user is already authenticated via getSession
2931 try {
3032 const existingSession = getSession ( ) ;
3133
3234 if ( existingSession ) {
33- // User is already authenticated, redirect to /
3435 await router . push ( "/" ) ;
3536 }
3637 } catch ( error ) {
@@ -40,7 +41,7 @@ function AuthHandler() {
4041 }
4142 } ;
4243 handleAsync ( ) ;
43- } , [ session , router ] ) ;
44+ } , [ apiBaseUrl , session , router ] ) ;
4445
4546 return null ; // This component only handles the auth logic
4647}
0 commit comments