Fix double mutation when non staff user logs in (#3565)

* Fix double externalObtainAccessTokens mutation when non-staff user logs in

* Fix double availableExternalAuthenticationsQuery

* Make available attributes query lazy
This commit is contained in:
Michał Droń 2023-06-19 11:05:02 +02:00 committed by GitHub
parent d5af778e7d
commit 37c36bfa3f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 20 additions and 8 deletions

View file

@ -11,7 +11,8 @@ export const useAuthParameters = () => {
);
return {
requestedExternalPluginId,
requestedExternalPluginId:
requestedExternalPluginId === "null" ? null : requestedExternalPluginId,
fallbackUri: fallbackUri === "null" || !fallbackUri ? "/" : fallbackUri,
isCallbackPath: location.pathname.includes(loginCallbackPath),
setRequestedExternalPluginId,

View file

@ -181,9 +181,12 @@ export function useAuthProvider({
};
const handleExternalLogin = async (
pluginId: string,
pluginId: string | undefined,
input: ExternalLoginInput,
) => {
if (!pluginId) {
return;
}
try {
const result = await getExternalAccessToken({
pluginId,

View file

@ -1,4 +1,4 @@
import { useAvailableExternalAuthenticationsQuery } from "@dashboard/graphql";
import { useAvailableExternalAuthenticationsLazyQuery } from "@dashboard/graphql";
import useNavigator from "@dashboard/hooks/useNavigator";
import { getAppMountUriForRedirect } from "@dashboard/utils/urls";
import React, { useEffect } from "react";
@ -25,11 +25,10 @@ const LoginView: React.FC<LoginViewProps> = ({ params }) => {
authenticating,
errors,
} = useUser();
const {
data: externalAuthentications,
loading: externalAuthenticationsLoading,
} = useAvailableExternalAuthenticationsQuery();
const [
queryExternalAuthentications,
{ data: externalAuthentications, loading: externalAuthenticationsLoading },
] = useAvailableExternalAuthenticationsLazyQuery();
const {
fallbackUri,
requestedExternalPluginId,
@ -72,6 +71,15 @@ const LoginView: React.FC<LoginViewProps> = ({ params }) => {
setFallbackUri(null);
};
useEffect(() => {
const { code, state } = params;
const externalAuthParamsExist = code && state && isCallbackPath;
if (!externalAuthParamsExist) {
queryExternalAuthentications();
}
}, [isCallbackPath, params, queryExternalAuthentications]);
useEffect(() => {
const { code, state } = params;
const externalAuthParamsExist = code && state && isCallbackPath;