feat(useAuthenticateApp): use REST API endpoint to create auth url
This commit is contained in:
@@ -54,12 +54,7 @@ const authenticationStepsWithAuthUrl = [
|
|||||||
{
|
{
|
||||||
type: 'mutation',
|
type: 'mutation',
|
||||||
name: 'generateAuthUrl',
|
name: 'generateAuthUrl',
|
||||||
arguments: [
|
arguments: [],
|
||||||
{
|
|
||||||
name: 'id',
|
|
||||||
value: '{createConnection.id}',
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
type: 'openWithPopup',
|
type: 'openWithPopup',
|
||||||
|
@@ -6,7 +6,7 @@ const computeAuthStepVariables = (variableSchema, aggregatedData) => {
|
|||||||
if (variable.properties) {
|
if (variable.properties) {
|
||||||
variables[variable.name] = computeAuthStepVariables(
|
variables[variable.name] = computeAuthStepVariables(
|
||||||
variable.properties,
|
variable.properties,
|
||||||
aggregatedData
|
aggregatedData,
|
||||||
);
|
);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -17,7 +17,7 @@ const computeAuthStepVariables = (variableSchema, aggregatedData) => {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
const computedVariable = template(variable.value, { interpolate })(
|
const computedVariable = template(variable.value, { interpolate })(
|
||||||
aggregatedData
|
aggregatedData,
|
||||||
);
|
);
|
||||||
variables[variable.name] = computedVariable;
|
variables[variable.name] = computedVariable;
|
||||||
}
|
}
|
||||||
|
@@ -9,6 +9,7 @@ import computeAuthStepVariables from 'helpers/computeAuthStepVariables';
|
|||||||
import useAppAuth from './useAppAuth';
|
import useAppAuth from './useAppAuth';
|
||||||
import useCreateConnection from './useCreateConnection';
|
import useCreateConnection from './useCreateConnection';
|
||||||
import useFormatMessage from './useFormatMessage';
|
import useFormatMessage from './useFormatMessage';
|
||||||
|
import useCreateConnectionAuthUrl from './useCreateConnectionAuthUrl';
|
||||||
|
|
||||||
function getSteps(auth, hasConnection, useShared) {
|
function getSteps(auth, hasConnection, useShared) {
|
||||||
if (hasConnection) {
|
if (hasConnection) {
|
||||||
@@ -29,6 +30,7 @@ export default function useAuthenticateApp(payload) {
|
|||||||
const { appKey, appAuthClientId, connectionId, useShared = false } = payload;
|
const { appKey, appAuthClientId, connectionId, useShared = false } = payload;
|
||||||
const { data: auth } = useAppAuth(appKey);
|
const { data: auth } = useAppAuth(appKey);
|
||||||
const { mutateAsync: createConnection } = useCreateConnection(appKey);
|
const { mutateAsync: createConnection } = useCreateConnection(appKey);
|
||||||
|
const { mutateAsync: createConnectionAuthUrl } = useCreateConnectionAuthUrl();
|
||||||
const [authenticationInProgress, setAuthenticationInProgress] =
|
const [authenticationInProgress, setAuthenticationInProgress] =
|
||||||
React.useState(false);
|
React.useState(false);
|
||||||
const formatMessage = useFormatMessage();
|
const formatMessage = useFormatMessage();
|
||||||
@@ -70,6 +72,11 @@ export default function useAuthenticateApp(payload) {
|
|||||||
if (step.name === 'createConnection') {
|
if (step.name === 'createConnection') {
|
||||||
const stepResponse = await createConnection(variables);
|
const stepResponse = await createConnection(variables);
|
||||||
response[step.name] = stepResponse?.data;
|
response[step.name] = stepResponse?.data;
|
||||||
|
} else if (step.name === 'generateAuthUrl') {
|
||||||
|
const stepResponse = await createConnectionAuthUrl(
|
||||||
|
response.createConnection.id,
|
||||||
|
);
|
||||||
|
response[step.name] = stepResponse?.data;
|
||||||
} else {
|
} else {
|
||||||
const stepResponse = await processMutation(step.name, variables);
|
const stepResponse = await processMutation(step.name, variables);
|
||||||
response[step.name] = stepResponse;
|
response[step.name] = stepResponse;
|
||||||
|
17
packages/web/src/hooks/useCreateConnectionAuthUrl.js
Normal file
17
packages/web/src/hooks/useCreateConnectionAuthUrl.js
Normal 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;
|
||||||
|
}
|
Reference in New Issue
Block a user