Handle Plugin Center Authentication failures (#1940)

If the plugin center authentication fails,
the plugins are fetched without authentication
and a warning is displayed on the plugin page.

Co-authored-by: Konstantin Schaper <konstantin.schaper@cloudogu.com>
This commit is contained in:
Sebastian Sdorra
2022-01-31 15:41:12 +01:00
committed by GitHub
parent 67bd96ea81
commit c74e9984f6
22 changed files with 505 additions and 117 deletions

View File

@@ -28,6 +28,16 @@ import { useMutation, useQuery, useQueryClient } from "react-query";
import { apiClient } from "./apiclient";
import { useLocation } from "react-router-dom";
const appendQueryParam = (link: Link, name: string, value: string) => {
let href = link.href;
if (href.includes("?")) {
href += "&";
} else {
href += "?";
}
link.href = href + name + "=" + value;
};
export const usePluginCenterAuthInfo = (): ApiResult<PluginCenterAuthenticationInfo> => {
const link = useIndexLink("pluginCenterAuth");
const location = useLocation();
@@ -42,7 +52,10 @@ export const usePluginCenterAuthInfo = (): ApiResult<PluginCenterAuthenticationI
.then(response => response.json())
.then((result: PluginCenterAuthenticationInfo) => {
if (result._links?.login) {
(result._links.login as Link).href += `?source=${location.pathname}`;
appendQueryParam(result._links.login as Link, "source", location.pathname);
}
if (result._links?.reconnect) {
appendQueryParam(result._links.reconnect as Link, "source", location.pathname);
}
return result;
});