Skip to content

Commit e6233b1

Browse files
authored
Merge pull request #5458 from marmelab/add-ability-to-disable-redirect-on-logout
Add ability to disable redirection after logout
2 parents 2fd8772 + 69fa621 commit e6233b1

File tree

3 files changed

+6
-2
lines changed

3 files changed

+6
-2
lines changed

docs/Authentication.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ export default {
176176

177177
The `authProvider` is also a good place to notify the authentication API that the user credentials are no longer valid after logout.
178178

179-
Note that the `authProvider.logout()` method can return the url to which the user will be redirected once logged out. By default, this is the `/login` route.
179+
Note that after logout, react-admin redirects the user to the string returned by `authProvider.logout()` - or to the `/login` url if the method returns nothing. You can customize the redirection url by returning a route string, or `false` to disable redirection after logout.
180180

181181
## Catching Authentication Errors On The API
182182

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

+4
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@ const useLogout = (): Logout => {
5050
) =>
5151
authProvider.logout(params).then(redirectToFromProvider => {
5252
dispatch(clearState());
53+
if (redirectToFromProvider === false) {
54+
// do not redirect
55+
return;
56+
}
5357
// redirectTo can contain a query string, e.g '/login?foo=bar'
5458
// we must split the redirectTo to pass a structured location to history.push()
5559
const redirectToParts = (

packages/ra-core/src/types.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ export interface UserIdentity {
6767
*/
6868
export type AuthProvider = {
6969
login: (params: any) => Promise<any>;
70-
logout: (params: any) => Promise<void | string>;
70+
logout: (params: any) => Promise<void | false | string>;
7171
checkAuth: (params: any) => Promise<void>;
7272
checkError: (error: any) => Promise<void>;
7373
getPermissions: (params: any) => Promise<any>;

0 commit comments

Comments
 (0)