Skip to content

Commit f75effd

Browse files
authored
Merge pull request #8382 from marmelab/fix-authProvider-redirectTo-absolute
Fix authProvider hooks support for redirectTo: absolute URL
2 parents 00ffc81 + 2a967c0 commit f75effd

File tree

2 files changed

+30
-13
lines changed

2 files changed

+30
-13
lines changed

packages/ra-core/src/auth/useLogout.ts

+14-5
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,20 @@ const useLogout = (): Logout => {
7070
// do not redirect
7171
return;
7272
}
73-
// redirectTo can contain a query string, e.g. '/login?foo=bar'
74-
// we must split the redirectTo to pass a structured location to navigate()
75-
const redirectToParts = (
76-
redirectToFromProvider || redirectTo
77-
).split('?');
73+
74+
const finalRedirectTo = redirectToFromProvider || redirectTo;
75+
76+
if (finalRedirectTo?.startsWith('http')) {
77+
// absolute link (e.g. https://my.oidc.server/login)
78+
resetStore();
79+
queryClient.clear();
80+
window.location.href = finalRedirectTo;
81+
return finalRedirectTo;
82+
}
83+
84+
// redirectTo is an internal location that may contain a query string, e.g. '/login?foo=bar'
85+
// we must split it to pass a structured location to navigate()
86+
const redirectToParts = finalRedirectTo.split('?');
7887
const newLocation: Partial<Path> = {
7988
pathname: redirectToParts[0],
8089
};

packages/ra-core/src/auth/useLogoutIfAccessDenied.ts

+16-8
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,18 @@ const useLogoutIfAccessDenied = (): LogoutIfAccessDenied => {
6060
timer = undefined;
6161
}, 0);
6262

63+
const redirectTo =
64+
e && e.redirectTo != null
65+
? e.redirectTo
66+
: error && error.redirectTo
67+
? error.redirectTo
68+
: undefined;
69+
6370
const shouldNotify = !(
6471
disableNotification ||
6572
(e && e.message === false) ||
66-
(error && error.message === false)
73+
(error && error.message === false) ||
74+
redirectTo?.startsWith('http')
6775
);
6876
if (shouldNotify) {
6977
// notify only if not yet logged out
@@ -90,17 +98,17 @@ const useLogoutIfAccessDenied = (): LogoutIfAccessDenied => {
9098
})
9199
.catch(() => {});
92100
}
93-
const redirectTo =
94-
e && e.redirectTo != null
95-
? e.redirectTo
96-
: error && error.redirectTo
97-
? error.redirectTo
98-
: undefined;
99101

100102
if (logoutUser) {
101103
logout({}, redirectTo);
102104
} else {
103-
navigate(redirectTo);
105+
if (redirectTo.startsWith('http')) {
106+
// absolute link (e.g. https://my.oidc.server/login)
107+
window.location.href = redirectTo;
108+
} else {
109+
// internal location
110+
navigate(redirectTo);
111+
}
104112
}
105113

106114
return true;

0 commit comments

Comments
 (0)