Skip to content

Commit 73d7c3f

Browse files
author
jadmsaadaot
authored
Merge pull request #135 from VineetBala-AOT/main
Preserve return path during OIDC sign-in redirect
2 parents ee3366d + f1fb50c commit 73d7c3f

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

condition-web/src/routes/_authenticated.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { createFileRoute, Navigate, Outlet } from "@tanstack/react-router";
44
import { useEffect } from "react";
55
import { useAuth } from "react-oidc-context";
66
import { useHasAllowedRoles, KeycloakRoles } from "@/hooks/useAuthorization";
7+
import { OidcConfig } from "@/utils/config";
78

89
export const Route = createFileRoute("/_authenticated")({
910
component: Auth,
@@ -27,7 +28,7 @@ function Auth() {
2728

2829
useEffect(() => {
2930
if (!isAuthenticated && !isUserAuthLoading) {
30-
signinRedirect();
31+
signinRedirect({redirect_uri: `${OidcConfig.redirect_uri}?path=${window.location.pathname}`});
3132
}
3233
}, [
3334
isAuthenticated,

condition-web/src/routes/oidc-callback.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ export const Route = createFileRoute("/oidc-callback")({
1111
function OidcCallback() {
1212
const { error: getAuthError, user: kcUser } = useAuth();
1313
const [isAuthLoading, setIsAuthLoading] = useState(true);
14+
const params = new URLSearchParams(window.location.search);
15+
const path = params.get("path");
1416

1517
useEffect(() => {
1618
if (kcUser) {
@@ -22,8 +24,9 @@ function OidcCallback() {
2224
guid: kcUser?.profile.sub,
2325
});
2426

25-
if (userData?.auth_guid) {
26-
return <Navigate to="/projects" />;
27+
if (userData?.auth_guid ) {
28+
const navPath = path ?? '/projects'
29+
return <Navigate to={navPath} />;
2730
}
2831

2932
if (getAuthError) {

0 commit comments

Comments
 (0)