@@ -5,7 +5,7 @@ import Loading from "@/app/utils/Loading";
55import { useRouter } from "next/navigation" ;
66import { checkUser } from "@/app/utils/auth" ;
77
8- export default function RegForm ( { email, instituteCode } ) {
8+ export default function RegForm ( { email, instituteCode, redirectUrl } ) {
99 const router = useRouter ( ) ;
1010 const [ loading , setLoading ] = useState ( true ) ;
1111 const [ formData , setFormData ] = useState ( {
@@ -17,14 +17,16 @@ export default function RegForm({ email, instituteCode }) {
1717
1818 const check = async ( ) => {
1919 if ( localStorage . getItem ( "travelbuddy" ) ) {
20- router . push ( "/" ) ;
20+ // Redirect to original destination or homepage if no redirect URL
21+ router . push ( redirectUrl ? decodeURIComponent ( redirectUrl ) : "/" ) ;
2122 return ;
2223 }
2324
2425 const user = await checkUser ( { email } ) ;
2526 if ( user ) {
2627 localStorage . setItem ( "travelbuddy" , user ) ;
27- router . push ( "/" ) ;
28+ // Redirect to original destination or homepage if no redirect URL
29+ router . push ( redirectUrl ? decodeURIComponent ( redirectUrl ) : "/" ) ;
2830 return ;
2931 }
3032
@@ -76,7 +78,8 @@ export default function RegForm({ email, instituteCode }) {
7678 const json = await res . json ( ) ;
7779 alert ( json . message ) ;
7880 localStorage . setItem ( "travelbuddy" , json . user ) ;
79- router . push ( "/" ) ;
81+ // Redirect to original destination or homepage if no redirect URL
82+ router . push ( redirectUrl ? decodeURIComponent ( redirectUrl ) : "/" ) ;
8083 } else {
8184 const json = await res . json ( ) ;
8285 alert ( json . message ) ;
0 commit comments