refactor(web): use oauth client instead of app auth client

This commit is contained in:
Ali BARIN
2024-12-19 14:53:47 +00:00
parent 8c4b67e147
commit 8d5287d51e
23 changed files with 206 additions and 194 deletions

View File

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

View File

@@ -1,20 +1,23 @@
import { useMutation, useQueryClient } from '@tanstack/react-query';
import api from 'helpers/api';
export default function useAdminCreateAppAuthClient(appKey) {
export default function useAdminCreateOAuthClient(appKey) {
const queryClient = useQueryClient();
const query = useMutation({
mutationFn: async (payload) => {
const { data } = await api.post(`/v1/admin/apps/${appKey}/auth-clients`, payload);
const { data } = await api.post(
`/v1/admin/apps/${appKey}/oauth-clients`,
payload,
);
return data;
},
onSuccess: () => {
queryClient.invalidateQueries({
queryKey: ['admin', 'apps', appKey, 'authClients'],
queryKey: ['admin', 'apps', appKey, 'oauthClients'],
});
}
},
});
return query;

View File

@@ -0,0 +1,22 @@
import { useQuery } from '@tanstack/react-query';
import api from 'helpers/api';
export default function useAdminOAuthClient(appKey, id) {
const query = useQuery({
queryKey: ['admin', 'apps', appKey, 'oauthClients', id],
queryFn: async ({ signal }) => {
const { data } = await api.get(
`/v1/admin/apps/${appKey}/oauth-clients/${id}`,
{
signal,
},
);
return data;
},
enabled: !!appKey && !!id,
});
return query;
}

View File

@@ -1,11 +1,11 @@
import { useQuery } from '@tanstack/react-query';
import api from 'helpers/api';
export default function useAdminAppAuthClients(appKey) {
export default function useAdminOAuthClients(appKey) {
const query = useQuery({
queryKey: ['admin', 'apps', appKey, 'authClients'],
queryKey: ['admin', 'apps', appKey, 'oauthClients'],
queryFn: async ({ signal }) => {
const { data } = await api.get(`/v1/admin/apps/${appKey}/auth-clients`, {
const { data } = await api.get(`/v1/admin/apps/${appKey}/oauth-clients`, {
signal,
});
return data;

View File

@@ -1,13 +1,13 @@
import { useMutation, useQueryClient } from '@tanstack/react-query';
import api from 'helpers/api';
export default function useAdminUpdateAppAuthClient(appKey, id) {
export default function useAdminUpdateOAuthClient(appKey, id) {
const queryClient = useQueryClient();
const query = useMutation({
const mutation = useMutation({
mutationFn: async (payload) => {
const { data } = await api.patch(
`/v1/admin/apps/${appKey}/auth-clients/${id}`,
`/v1/admin/apps/${appKey}/oauth-clients/${id}`,
payload,
);
@@ -15,14 +15,14 @@ export default function useAdminUpdateAppAuthClient(appKey, id) {
},
onSuccess: () => {
queryClient.invalidateQueries({
queryKey: ['admin', 'apps', appKey, 'authClients', id],
queryKey: ['admin', 'apps', appKey, 'oauthClients', id],
});
queryClient.invalidateQueries({
queryKey: ['admin', 'apps', appKey, 'authClients'],
queryKey: ['admin', 'apps', appKey, 'oauthClients'],
});
},
});
return query;
return mutation;
}

View File

@@ -31,7 +31,7 @@ function getSteps(auth, hasConnection, useShared) {
}
export default function useAuthenticateApp(payload) {
const { appKey, appAuthClientId, connectionId, useShared = false } = payload;
const { appKey, oauthClientId, connectionId, useShared = false } = payload;
const { data: auth } = useAppAuth(appKey);
const queryClient = useQueryClient();
const { mutateAsync: createConnection } = useCreateConnection(appKey);
@@ -55,7 +55,7 @@ export default function useAuthenticateApp(payload) {
const response = {
key: appKey,
appAuthClientId: appAuthClientId || payload.appAuthClientId,
oauthClientId: oauthClientId || payload.oauthClientId,
connectionId,
fields,
};
@@ -133,7 +133,7 @@ export default function useAuthenticateApp(payload) {
}, [
steps,
appKey,
appAuthClientId,
oauthClientId,
connectionId,
queryClient,
createConnection,
@@ -147,7 +147,7 @@ export default function useAuthenticateApp(payload) {
[
steps,
appKey,
appAuthClientId,
oauthClientId,
connectionId,
queryClient,
createConnection,
@@ -156,7 +156,7 @@ export default function useAuthenticateApp(payload) {
resetConnection,
verifyConnection,
],
'steps, appKey, appAuthClientId, connectionId, queryClient, createConnection, createConnectionAuthUrl, updateConnection, resetConnection, verifyConnection',
'steps, appKey, oauthClientId, connectionId, queryClient, createConnection, createConnectionAuthUrl, updateConnection, resetConnection, verifyConnection',
'',
'useAuthenticate',
);

View File

@@ -4,9 +4,9 @@ import api from 'helpers/api';
export default function useCreateConnection(appKey) {
const mutation = useMutation({
mutationFn: async ({ appAuthClientId, formattedData }) => {
mutationFn: async ({ oauthClientId, formattedData }) => {
const { data } = await api.post(`/v1/apps/${appKey}/connections`, {
appAuthClientId,
oauthClientId,
formattedData,
});

View File

@@ -1,11 +1,11 @@
import { useQuery } from '@tanstack/react-query';
import api from 'helpers/api';
export default function useAppAuthClients(appKey) {
export default function useOAuthClients(appKey) {
const query = useQuery({
queryKey: ['apps', appKey, 'auth-clients'],
queryKey: ['apps', appKey, 'oauth-clients'],
queryFn: async ({ signal }) => {
const { data } = await api.get(`/v1/apps/${appKey}/auth-clients`, {
const { data } = await api.get(`/v1/apps/${appKey}/oauth-clients`, {
signal,
});
return data;

View File

@@ -4,10 +4,10 @@ import api from 'helpers/api';
export default function useUpdateConnection() {
const query = useMutation({
mutationFn: async ({ connectionId, formattedData, appAuthClientId }) => {
mutationFn: async ({ connectionId, formattedData, oauthClientId }) => {
const { data } = await api.patch(`/v1/connections/${connectionId}`, {
formattedData,
appAuthClientId,
oauthClientId,
});
return data;