mirror of
https://github.com/ZeppelinBot/Zeppelin.git
synced 2025-03-15 05:41:51 +00:00
Detect expired dashboard logins and redirect to the splash page
This commit is contained in:
parent
f3a90faaa7
commit
8f5a9e607a
4 changed files with 12 additions and 1 deletions
|
@ -167,7 +167,7 @@ export function apiTokenAuthHandlers() {
|
||||||
return [
|
return [
|
||||||
passport.authenticate("api-token", { failWithError: true }),
|
passport.authenticate("api-token", { failWithError: true }),
|
||||||
(err, req: Request, res: Response, next) => {
|
(err, req: Request, res: Response, next) => {
|
||||||
return res.json({ error: err.message });
|
return res.status(401).json({ error: err.message });
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,6 +30,11 @@ function buildQueryString(params: QueryParamObject) {
|
||||||
export function request(resource, fetchOpts: RequestInit = {}) {
|
export function request(resource, fetchOpts: RequestInit = {}) {
|
||||||
return fetch(`${apiUrl}/${resource}`, fetchOpts).then(async res => {
|
return fetch(`${apiUrl}/${resource}`, fetchOpts).then(async res => {
|
||||||
if (!res.ok) {
|
if (!res.ok) {
|
||||||
|
if (res.status === 401) {
|
||||||
|
RootStore.dispatch("auth/expiredLogin");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const body = await res.json();
|
const body = await res.json();
|
||||||
throw new ApiError(res.statusText, body, res.status, res);
|
throw new ApiError(res.statusText, body, res.status, res);
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,6 +22,7 @@ if (window.location.pathname !== "/") {
|
||||||
|
|
||||||
const errorMessages = {
|
const errorMessages = {
|
||||||
noAccess: "No dashboard access. If you think this is a mistake, please contact your server owner.",
|
noAccess: "No dashboard access. If you think this is a mistake, please contact your server owner.",
|
||||||
|
expiredLogin: "Dashboard login expired. Please log in again.",
|
||||||
};
|
};
|
||||||
|
|
||||||
const errorMessageElem = document.createElement("div");
|
const errorMessageElem = document.createElement("div");
|
||||||
|
|
|
@ -71,6 +71,11 @@ export const AuthStore: Module<AuthState, RootState> = {
|
||||||
await post("auth/logout");
|
await post("auth/logout");
|
||||||
await dispatch("clearApiKey");
|
await dispatch("clearApiKey");
|
||||||
},
|
},
|
||||||
|
|
||||||
|
async expiredLogin({ dispatch }) {
|
||||||
|
await dispatch("clearApiKey");
|
||||||
|
window.location.assign("/?error=expiredLogin");
|
||||||
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
mutations: {
|
mutations: {
|
||||||
|
|
Loading…
Add table
Reference in a new issue