feat: add useAppAuth with RQ

This commit is contained in:
Rıdvan Akca
2024-03-07 15:54:00 +03:00
parent a4c0edf493
commit 2ee5af8bfb
8 changed files with 68 additions and 53 deletions

View File

@@ -0,0 +1,19 @@
import { useQuery } from '@tanstack/react-query';
import api from 'helpers/api';
export default function useAppAuth(appKey) {
const query = useQuery({
queryKey: ['appAuth', appKey],
queryFn: async ({ payload, signal }) => {
const { data } = await api.get(`/v1/apps/${appKey}/auth`, {
signal,
});
return data;
},
enabled: !!appKey,
});
return query;
}

View File

@@ -2,7 +2,7 @@ import * as React from 'react';
import { processStep } from 'helpers/authenticationSteps';
import computeAuthStepVariables from 'helpers/computeAuthStepVariables';
import useApp from './useApp';
import useAppAuth from './useAppAuth';
function getSteps(auth, hasConnection, useShared) {
if (hasConnection) {
@@ -21,10 +21,10 @@ function getSteps(auth, hasConnection, useShared) {
export default function useAuthenticateApp(payload) {
const { appKey, appAuthClientId, connectionId, useShared = false } = payload;
const { data: app } = useApp(appKey);
const { data: auth } = useAppAuth(appKey);
const [authenticationInProgress, setAuthenticationInProgress] =
React.useState(false);
const steps = getSteps(app?.data?.auth, !!connectionId, useShared);
const steps = getSteps(auth?.data, !!connectionId, useShared);
const authenticate = React.useMemo(() => {
if (!steps?.length) return;