mirror of
https://github.com/casdoor/casdoor.git
synced 2025-07-05 05:50:19 +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 {confirm} = Modal;
|
||||||
const {fetch: originalFetch} = window;
|
const {fetch: originalFetch} = window;
|
||||||
|
|
||||||
const demoModeCallback = async(url, option) => {
|
const demoModeCallback = (res) => {
|
||||||
if (option.method === "POST") {
|
res.json().then(data => {
|
||||||
|
if (data.msg === "Unauthorized operation") {
|
||||||
confirm({
|
confirm({
|
||||||
title: i18next.t("general:This is a read-only demo site!"),
|
title: i18next.t("general:This is a read-only demo site!"),
|
||||||
icon: <ExclamationCircleFilled />,
|
icon: <ExclamationCircleFilled />,
|
||||||
@ -35,21 +36,23 @@ const demoModeCallback = async(url, option) => {
|
|||||||
onCancel() {},
|
onCancel() {},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
});
|
||||||
return option;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const requestFilters = [];
|
const requestFilters = [];
|
||||||
const responseFilters = [];
|
const responseFilters = [];
|
||||||
|
|
||||||
if (Conf.IsDemoMode) {
|
if (Conf.IsDemoMode) {
|
||||||
requestFilters.push(demoModeCallback);
|
responseFilters.push(demoModeCallback);
|
||||||
}
|
}
|
||||||
|
|
||||||
window.fetch = async(url, option = {}) => {
|
window.fetch = async(url, option = {}) => {
|
||||||
requestFilters.forEach(filter => filter(url, option));
|
requestFilters.forEach(filter => filter(url, option));
|
||||||
|
|
||||||
const response = await originalFetch(url, option);
|
return new Promise((resolve, reject) => {
|
||||||
responseFilters.forEach(filter => (response) => filter(response));
|
originalFetch(url, option).then(res => {
|
||||||
return response;
|
responseFilters.forEach(filter => filter(res.clone()));
|
||||||
|
resolve(res);
|
||||||
|
});
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
Reference in New Issue
Block a user