File tree Expand file tree Collapse file tree 2 files changed +18
-2
lines changed
Expand file tree Collapse file tree 2 files changed +18
-2
lines changed Original file line number Diff line number Diff line change @@ -18,8 +18,12 @@ export default function AuthGuard({ children }: AuthGuardProps) {
1818 setIsAuthenticated ( true ) ;
1919 } else {
2020 setIsAuthenticated ( false ) ;
21- // Redirect to login
22- window . location . href = `${ EXTERNAL . directus_url } /auth/login/authentik?redirect=${ encodeURIComponent ( window . location . href ) } ` ;
21+ // Get the next path from URL params or current path
22+ const urlParams = new URLSearchParams ( window . location . search ) ;
23+ const nextPath = urlParams . get ( 'next' ) || window . location . pathname + window . location . search ;
24+
25+ const callbackUrl = `${ window . location . origin } /?next=${ encodeURIComponent ( nextPath ) } ` ;
26+ window . location . href = `${ EXTERNAL . directus_url } /auth/login/authentik?redirect=${ encodeURIComponent ( callbackUrl ) } ` ;
2327 }
2428 }
2529
Original file line number Diff line number Diff line change @@ -25,4 +25,16 @@ import Products from "../components/Products.astro";
2525 <!-- <CallToAction /> -->
2626 <Footer />
2727 </main >
28+
29+ <script >
30+ // Handle post-authentication redirect
31+ const urlParams = new URLSearchParams(window.location.search);
32+ const nextPath = urlParams.get('next');
33+
34+ if (nextPath) {
35+ // Clean up the URL and redirect
36+ window.history.replaceState({}, document.title, window.location.pathname);
37+ window.location.href = nextPath;
38+ }
39+ </script >
2840</Layout >
You can’t perform that action at this time.
0 commit comments