feat(useAuthenticateApp): use REST API endpoint to create auth url

This commit is contained in:
Ali BARIN
2024-09-24 09:28:17 +00:00
parent 01407cf040
commit 7dcfb1081b
4 changed files with 27 additions and 8 deletions

View File

@@ -54,12 +54,7 @@ const authenticationStepsWithAuthUrl = [
{
type: 'mutation',
name: 'generateAuthUrl',
arguments: [
{
name: 'id',
value: '{createConnection.id}',
},
],
arguments: [],
},
{
type: 'openWithPopup',

View File

@@ -6,7 +6,7 @@ const computeAuthStepVariables = (variableSchema, aggregatedData) => {
if (variable.properties) {
variables[variable.name] = computeAuthStepVariables(
variable.properties,
aggregatedData
aggregatedData,
);
continue;
}
@@ -17,7 +17,7 @@ const computeAuthStepVariables = (variableSchema, aggregatedData) => {
continue;
}
const computedVariable = template(variable.value, { interpolate })(
aggregatedData
aggregatedData,
);
variables[variable.name] = computedVariable;
}

View File

@@ -9,6 +9,7 @@ import computeAuthStepVariables from 'helpers/computeAuthStepVariables';
import useAppAuth from './useAppAuth';
import useCreateConnection from './useCreateConnection';
import useFormatMessage from './useFormatMessage';
import useCreateConnectionAuthUrl from './useCreateConnectionAuthUrl';
function getSteps(auth, hasConnection, useShared) {
if (hasConnection) {
@@ -29,6 +30,7 @@ export default function useAuthenticateApp(payload) {
const { appKey, appAuthClientId, connectionId, useShared = false } = payload;
const { data: auth } = useAppAuth(appKey);
const { mutateAsync: createConnection } = useCreateConnection(appKey);
const { mutateAsync: createConnectionAuthUrl } = useCreateConnectionAuthUrl();
const [authenticationInProgress, setAuthenticationInProgress] =
React.useState(false);
const formatMessage = useFormatMessage();
@@ -70,6 +72,11 @@ export default function useAuthenticateApp(payload) {
if (step.name === 'createConnection') {
const stepResponse = await createConnection(variables);
response[step.name] = stepResponse?.data;
} else if (step.name === 'generateAuthUrl') {
const stepResponse = await createConnectionAuthUrl(
response.createConnection.id,
);
response[step.name] = stepResponse?.data;
} else {
const stepResponse = await processMutation(step.name, variables);
response[step.name] = stepResponse;

View File

@@ -0,0 +1,17 @@
import { useMutation } from '@tanstack/react-query';
import api from 'helpers/api';
export default function useCreateConnectionAuthUrl() {
const query = useMutation({
mutationFn: async (connectionId) => {
const { data } = await api.post(
`/v1/connections/${connectionId}/auth-url`,
);
return data;
},
});
return query;
}