mirror of
https://github.com/casdoor/casdoor.git
synced 2025-07-04 21:30:24 +08:00
fix: detect access denied by response message for demo mode (#1565)
fix: detect access denied by response message for demo mode
This commit is contained in:
@ -21,8 +21,9 @@ import * as Setting from "../Setting";
|
||||
const {confirm} = Modal;
|
||||
const {fetch: originalFetch} = window;
|
||||
|
||||
const demoModeCallback = async(url, option) => {
|
||||
if (option.method === "POST") {
|
||||
const demoModeCallback = (res) => {
|
||||
res.json().then(data => {
|
||||
if (data.msg === "Unauthorized operation") {
|
||||
confirm({
|
||||
title: i18next.t("general:This is a read-only demo site!"),
|
||||
icon: <ExclamationCircleFilled />,
|
||||
@ -35,21 +36,23 @@ const demoModeCallback = async(url, option) => {
|
||||
onCancel() {},
|
||||
});
|
||||
}
|
||||
|
||||
return option;
|
||||
});
|
||||
};
|
||||
|
||||
const requestFilters = [];
|
||||
const responseFilters = [];
|
||||
|
||||
if (Conf.IsDemoMode) {
|
||||
requestFilters.push(demoModeCallback);
|
||||
responseFilters.push(demoModeCallback);
|
||||
}
|
||||
|
||||
window.fetch = async(url, option = {}) => {
|
||||
requestFilters.forEach(filter => filter(url, option));
|
||||
|
||||
const response = await originalFetch(url, option);
|
||||
responseFilters.forEach(filter => (response) => filter(response));
|
||||
return response;
|
||||
return new Promise((resolve, reject) => {
|
||||
originalFetch(url, option).then(res => {
|
||||
responseFilters.forEach(filter => filter(res.clone()));
|
||||
resolve(res);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
Reference in New Issue
Block a user