Skip to content

Commit 9baee44

Browse files
author
HH: Andrico Karoulla
committed
remove unnecessary code, add notification when redirected via not being authorized
1 parent da68b1a commit 9baee44

File tree

3 files changed

+16
-16
lines changed

3 files changed

+16
-16
lines changed

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

+13-16
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,17 @@ const useLogoutIfAccessDenied = (): LogoutIfAccessDenied => {
7171
authProvider
7272
.checkAuth({})
7373
.then(() => {
74-
notify('ra.notification.logged_out', 'warning');
74+
if (logoutUser) {
75+
notify(
76+
'ra.notification.logged_out',
77+
'warning'
78+
);
79+
} else {
80+
notify(
81+
'ra.notification.not_authorized',
82+
'warning'
83+
);
84+
}
7585
})
7686
.catch(() => {});
7787
}
@@ -85,24 +95,11 @@ const useLogoutIfAccessDenied = (): LogoutIfAccessDenied => {
8595
if (logoutUser) {
8696
logout({}, redirectTo);
8797
} else {
88-
const redirectToParts = redirectTo.split('?');
8998
const newLocation: LocationDescriptorObject = {
90-
pathname: redirectToParts[0],
99+
pathname: redirectTo,
91100
};
92101

93-
if (history.location && history.location.pathname) {
94-
newLocation.state = {
95-
nextPathname: history.location.pathname,
96-
nextSearch: history.location.search,
97-
};
98-
}
99-
100-
if (redirectToParts[1]) {
101-
newLocation.search = redirectToParts[1];
102-
}
103-
history.push(redirectTo);
104-
105-
return false;
102+
history.push(newLocation);
106103
}
107104

108105
return true;

packages/ra-language-english/src/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ const englishMessages: TranslationMessages = {
138138
'Cannot load the translations for the specified language',
139139
canceled: 'Action cancelled',
140140
logged_out: 'Your session has ended, please reconnect.',
141+
not_authorized: "You're not authorized to access this resource.",
141142
},
142143
validation: {
143144
required: 'Required',

packages/ra-language-french/src/index.ts

+2
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,8 @@ const frenchMessages: TranslationMessages = {
143143
'Erreur de chargement des traductions pour la langue sélectionnée',
144144
canceled: 'Action annulée',
145145
logged_out: 'Votre session a pris fin, veuillez vous reconnecter.',
146+
not_authorized:
147+
"Vous n'êtes pas autorisé à accéder à cette ressource.",
146148
},
147149
validation: {
148150
required: 'Ce champ est requis',

0 commit comments

Comments
 (0)