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 {
|
return {
|
||||||
requestedExternalPluginId,
|
requestedExternalPluginId:
|
||||||
|
requestedExternalPluginId === "null" ? null : requestedExternalPluginId,
|
||||||
fallbackUri: fallbackUri === "null" || !fallbackUri ? "/" : fallbackUri,
|
fallbackUri: fallbackUri === "null" || !fallbackUri ? "/" : fallbackUri,
|
||||||
isCallbackPath: location.pathname.includes(loginCallbackPath),
|
isCallbackPath: location.pathname.includes(loginCallbackPath),
|
||||||
setRequestedExternalPluginId,
|
setRequestedExternalPluginId,
|
||||||
|
|
|
@ -181,9 +181,12 @@ export function useAuthProvider({
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleExternalLogin = async (
|
const handleExternalLogin = async (
|
||||||
pluginId: string,
|
pluginId: string | undefined,
|
||||||
input: ExternalLoginInput,
|
input: ExternalLoginInput,
|
||||||
) => {
|
) => {
|
||||||
|
if (!pluginId) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
const result = await getExternalAccessToken({
|
const result = await getExternalAccessToken({
|
||||||
pluginId,
|
pluginId,
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import { useAvailableExternalAuthenticationsQuery } from "@dashboard/graphql";
|
import { useAvailableExternalAuthenticationsLazyQuery } from "@dashboard/graphql";
|
||||||
import useNavigator from "@dashboard/hooks/useNavigator";
|
import useNavigator from "@dashboard/hooks/useNavigator";
|
||||||
import { getAppMountUriForRedirect } from "@dashboard/utils/urls";
|
import { getAppMountUriForRedirect } from "@dashboard/utils/urls";
|
||||||
import React, { useEffect } from "react";
|
import React, { useEffect } from "react";
|
||||||
|
@ -25,11 +25,10 @@ const LoginView: React.FC<LoginViewProps> = ({ params }) => {
|
||||||
authenticating,
|
authenticating,
|
||||||
errors,
|
errors,
|
||||||
} = useUser();
|
} = useUser();
|
||||||
const {
|
const [
|
||||||
data: externalAuthentications,
|
queryExternalAuthentications,
|
||||||
loading: externalAuthenticationsLoading,
|
{ data: externalAuthentications, loading: externalAuthenticationsLoading },
|
||||||
} = useAvailableExternalAuthenticationsQuery();
|
] = useAvailableExternalAuthenticationsLazyQuery();
|
||||||
|
|
||||||
const {
|
const {
|
||||||
fallbackUri,
|
fallbackUri,
|
||||||
requestedExternalPluginId,
|
requestedExternalPluginId,
|
||||||
|
@ -72,6 +71,15 @@ const LoginView: React.FC<LoginViewProps> = ({ params }) => {
|
||||||
setFallbackUri(null);
|
setFallbackUri(null);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const { code, state } = params;
|
||||||
|
const externalAuthParamsExist = code && state && isCallbackPath;
|
||||||
|
|
||||||
|
if (!externalAuthParamsExist) {
|
||||||
|
queryExternalAuthentications();
|
||||||
|
}
|
||||||
|
}, [isCallbackPath, params, queryExternalAuthentications]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const { code, state } = params;
|
const { code, state } = params;
|
||||||
const externalAuthParamsExist = code && state && isCallbackPath;
|
const externalAuthParamsExist = code && state && isCallbackPath;
|
||||||
|
|
Loading…
Reference in a new issue