refactor: remove get-current-user GQL query
This commit is contained in:
@@ -1,5 +0,0 @@
|
||||
const getCurrentUser = async (_parent, _params, context) => {
|
||||
return context.currentUser;
|
||||
};
|
||||
|
||||
export default getCurrentUser;
|
@@ -1,79 +0,0 @@
|
||||
import { describe, it, expect, beforeEach } from 'vitest';
|
||||
import request from 'supertest';
|
||||
import app from '../../app';
|
||||
import createAuthTokenByUserId from '../../helpers/create-auth-token-by-user-id';
|
||||
import { createRole } from '../../../test/factories/role';
|
||||
import { createUser } from '../../../test/factories/user';
|
||||
|
||||
describe('graphQL getCurrentUser query', () => {
|
||||
let role, currentUser, token, requestObject;
|
||||
|
||||
beforeEach(async () => {
|
||||
role = await createRole({
|
||||
key: 'sample',
|
||||
name: 'sample',
|
||||
});
|
||||
|
||||
currentUser = await createUser({
|
||||
roleId: role.id,
|
||||
});
|
||||
|
||||
token = createAuthTokenByUserId(currentUser.id);
|
||||
requestObject = request(app).post('/graphql').set('Authorization', token);
|
||||
});
|
||||
|
||||
it('should return user data', async () => {
|
||||
const query = `
|
||||
query {
|
||||
getCurrentUser {
|
||||
id
|
||||
email
|
||||
fullName
|
||||
email
|
||||
createdAt
|
||||
updatedAt
|
||||
role {
|
||||
id
|
||||
name
|
||||
}
|
||||
}
|
||||
}
|
||||
`;
|
||||
|
||||
const response = await requestObject.send({ query }).expect(200);
|
||||
|
||||
const expectedResponsePayload = {
|
||||
data: {
|
||||
getCurrentUser: {
|
||||
createdAt: currentUser.createdAt.getTime().toString(),
|
||||
email: currentUser.email,
|
||||
fullName: currentUser.fullName,
|
||||
id: currentUser.id,
|
||||
role: { id: role.id, name: role.name },
|
||||
updatedAt: currentUser.updatedAt.getTime().toString(),
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
expect(response.body).toEqual(expectedResponsePayload);
|
||||
});
|
||||
|
||||
it('should not return user password', async () => {
|
||||
const query = `
|
||||
query {
|
||||
getCurrentUser {
|
||||
id
|
||||
email
|
||||
password
|
||||
}
|
||||
}
|
||||
`;
|
||||
|
||||
const response = await requestObject.send({ query }).expect(400);
|
||||
|
||||
expect(response.body.errors).toBeDefined();
|
||||
expect(response.body.errors[0].message).toEqual(
|
||||
'Cannot query field "password" on type "User".'
|
||||
);
|
||||
});
|
||||
});
|
@@ -4,7 +4,6 @@ import getAppAuthClients from './queries/get-app-auth-clients.ee.js';
|
||||
import getBillingAndUsage from './queries/get-billing-and-usage.ee.js';
|
||||
import getConfig from './queries/get-config.ee.js';
|
||||
import getConnectedApps from './queries/get-connected-apps.js';
|
||||
import getCurrentUser from './queries/get-current-user.js';
|
||||
import getDynamicData from './queries/get-dynamic-data.js';
|
||||
import getDynamicFields from './queries/get-dynamic-fields.js';
|
||||
import getFlow from './queries/get-flow.js';
|
||||
@@ -32,7 +31,6 @@ const queryResolvers = {
|
||||
getBillingAndUsage,
|
||||
getConfig,
|
||||
getConnectedApps,
|
||||
getCurrentUser,
|
||||
getDynamicData,
|
||||
getDynamicFields,
|
||||
getFlow,
|
||||
|
@@ -24,7 +24,6 @@ type Query {
|
||||
parameters: JSONObject
|
||||
): [SubstepArgument]
|
||||
getBillingAndUsage: GetBillingAndUsage
|
||||
getCurrentUser: User
|
||||
getConfig(keys: [String]): JSONObject
|
||||
getInvoices: [Invoice]
|
||||
getPermissionCatalog: PermissionCatalog
|
||||
|
@@ -14,7 +14,8 @@ import useCurrentUser from 'hooks/useCurrentUser';
|
||||
function DeleteAccountDialog(props) {
|
||||
const [deleteCurrentUser] = useMutation(DELETE_CURRENT_USER);
|
||||
const formatMessage = useFormatMessage();
|
||||
const { data: currentUser } = useCurrentUser();
|
||||
const { data } = useCurrentUser();
|
||||
const currentUser = data?.data;
|
||||
|
||||
const authentication = useAuthentication();
|
||||
const navigate = useNavigate();
|
||||
@@ -24,7 +25,7 @@ function DeleteAccountDialog(props) {
|
||||
authentication.updateToken('');
|
||||
await apolloClient.clearStore();
|
||||
navigate(URLS.LOGIN);
|
||||
}, [deleteCurrentUser, currentUser?.data]);
|
||||
}, [deleteCurrentUser, currentUser]);
|
||||
|
||||
return (
|
||||
<ConfirmationDialog
|
||||
|
@@ -7,7 +7,8 @@ import useCurrentUser from 'hooks/useCurrentUser';
|
||||
|
||||
const Chatwoot = ({ ready }) => {
|
||||
const theme = useTheme();
|
||||
const { data: currentUser } = useCurrentUser();
|
||||
const { data } = useCurrentUser();
|
||||
const currentUser = data?.data;
|
||||
const matchSmallScreens = useMediaQuery(theme.breakpoints.down('md'));
|
||||
|
||||
React.useEffect(function initiateChatwoot() {
|
||||
@@ -24,17 +25,17 @@ const Chatwoot = ({ ready }) => {
|
||||
|
||||
React.useEffect(
|
||||
function initiateUser() {
|
||||
if (!currentUser?.data?.id || !ready) return;
|
||||
window.$chatwoot.setUser(currentUser.data?.id, {
|
||||
email: currentUser?.data?.email,
|
||||
name: currentUser?.data?.fullName,
|
||||
if (!currentUser?.id || !ready) return;
|
||||
window.$chatwoot.setUser(currentUser.id, {
|
||||
email: currentUser.email,
|
||||
name: currentUser.fullName,
|
||||
});
|
||||
|
||||
if (!matchSmallScreens) {
|
||||
window.$chatwoot.toggleBubbleVisibility('show');
|
||||
}
|
||||
},
|
||||
[currentUser?.data, ready, matchSmallScreens],
|
||||
[currentUser, ready, matchSmallScreens],
|
||||
);
|
||||
React.useLayoutEffect(
|
||||
function hideChatwoot() {
|
||||
|
@@ -21,7 +21,8 @@ import usePaddle from 'hooks/usePaddle.ee';
|
||||
|
||||
export default function UpgradeFreeTrial() {
|
||||
const { data: plans, isLoading: isPaymentPlansLoading } = usePaymentPlans();
|
||||
const { data: currentUser } = useCurrentUser();
|
||||
const { data } = useCurrentUser();
|
||||
const currentUser = data?.data;
|
||||
const { loaded: paddleLoaded } = usePaddle();
|
||||
const [selectedIndex, setSelectedIndex] = React.useState(0);
|
||||
const selectedPlan = plans?.data?.[selectedIndex];
|
||||
@@ -30,13 +31,13 @@ export default function UpgradeFreeTrial() {
|
||||
const handleCheckout = React.useCallback(() => {
|
||||
window.Paddle.Checkout?.open({
|
||||
product: selectedPlan.productId,
|
||||
email: currentUser?.data?.email,
|
||||
email: currentUser?.email,
|
||||
passthrough: JSON.stringify({
|
||||
id: currentUser?.data?.id,
|
||||
email: currentUser?.data?.email,
|
||||
id: currentUser?.id,
|
||||
email: currentUser?.email,
|
||||
}),
|
||||
});
|
||||
}, [selectedPlan, currentUser?.data]);
|
||||
}, [selectedPlan, currentUser]);
|
||||
|
||||
if (isPaymentPlansLoading || !plans?.data?.length) return null;
|
||||
|
||||
|
@@ -1,20 +0,0 @@
|
||||
import { gql } from '@apollo/client';
|
||||
export const GET_CURRENT_USER = gql`
|
||||
query GetCurrentUser {
|
||||
getCurrentUser {
|
||||
id
|
||||
fullName
|
||||
email
|
||||
role {
|
||||
id
|
||||
isAdmin
|
||||
}
|
||||
permissions {
|
||||
id
|
||||
action
|
||||
subject
|
||||
conditions
|
||||
}
|
||||
}
|
||||
}
|
||||
`;
|
@@ -40,7 +40,8 @@ function ProfileSettings() {
|
||||
const [showDeleteAccountConfirmation, setShowDeleteAccountConfirmation] =
|
||||
React.useState(false);
|
||||
const enqueueSnackbar = useEnqueueSnackbar();
|
||||
const { data: currentUser } = useCurrentUser();
|
||||
const { data } = useCurrentUser();
|
||||
const currentUser = data?.data;
|
||||
const formatMessage = useFormatMessage();
|
||||
const [updateCurrentUser] = useMutation(UPDATE_CURRENT_USER);
|
||||
|
||||
@@ -62,7 +63,7 @@ function ProfileSettings() {
|
||||
optimisticResponse: {
|
||||
updateCurrentUser: {
|
||||
__typename: 'User',
|
||||
id: currentUser?.data?.id,
|
||||
id: currentUser?.id,
|
||||
fullName,
|
||||
email,
|
||||
},
|
||||
@@ -87,7 +88,7 @@ function ProfileSettings() {
|
||||
<Grid item xs={12} justifyContent="flex-end">
|
||||
<StyledForm
|
||||
defaultValues={{
|
||||
...currentUser?.data,
|
||||
...currentUser,
|
||||
password: '',
|
||||
confirmPassword: '',
|
||||
}}
|
||||
|
Reference in New Issue
Block a user