Skip to content

Commit 6d4a8de

Browse files
committed
redirect set up
1 parent c983c37 commit 6d4a8de

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

src/components/interactive/AuthGuard.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff 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

src/pages/index.astro

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff 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>

0 commit comments

Comments
 (0)