feat(useAuthenticateApp): use REST API endpoint to create auth url
This commit is contained in:
@@ -54,12 +54,7 @@ const authenticationStepsWithAuthUrl = [
|
||||
{
|
||||
type: 'mutation',
|
||||
name: 'generateAuthUrl',
|
||||
arguments: [
|
||||
{
|
||||
name: 'id',
|
||||
value: '{createConnection.id}',
|
||||
},
|
||||
],
|
||||
arguments: [],
|
||||
},
|
||||
{
|
||||
type: 'openWithPopup',
|
||||
|
@@ -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;
|
||||
}
|
||||
|
@@ -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;
|
||||
|
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