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:
parent
d5af778e7d
commit
37c36bfa3f
3 changed files with 20 additions and 8 deletions
|
@ -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,
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue