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 getBillingAndUsage from './queries/get-billing-and-usage.ee.js';
|
||||||
import getConfig from './queries/get-config.ee.js';
|
import getConfig from './queries/get-config.ee.js';
|
||||||
import getConnectedApps from './queries/get-connected-apps.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 getDynamicData from './queries/get-dynamic-data.js';
|
||||||
import getDynamicFields from './queries/get-dynamic-fields.js';
|
import getDynamicFields from './queries/get-dynamic-fields.js';
|
||||||
import getFlow from './queries/get-flow.js';
|
import getFlow from './queries/get-flow.js';
|
||||||
@@ -32,7 +31,6 @@ const queryResolvers = {
|
|||||||
getBillingAndUsage,
|
getBillingAndUsage,
|
||||||
getConfig,
|
getConfig,
|
||||||
getConnectedApps,
|
getConnectedApps,
|
||||||
getCurrentUser,
|
|
||||||
getDynamicData,
|
getDynamicData,
|
||||||
getDynamicFields,
|
getDynamicFields,
|
||||||
getFlow,
|
getFlow,
|
||||||
|
@@ -24,7 +24,6 @@ type Query {
|
|||||||
parameters: JSONObject
|
parameters: JSONObject
|
||||||
): [SubstepArgument]
|
): [SubstepArgument]
|
||||||
getBillingAndUsage: GetBillingAndUsage
|
getBillingAndUsage: GetBillingAndUsage
|
||||||
getCurrentUser: User
|
|
||||||
getConfig(keys: [String]): JSONObject
|
getConfig(keys: [String]): JSONObject
|
||||||
getInvoices: [Invoice]
|
getInvoices: [Invoice]
|
||||||
getPermissionCatalog: PermissionCatalog
|
getPermissionCatalog: PermissionCatalog
|
||||||
|
@@ -14,7 +14,8 @@ import useCurrentUser from 'hooks/useCurrentUser';
|
|||||||
function DeleteAccountDialog(props) {
|
function DeleteAccountDialog(props) {
|
||||||
const [deleteCurrentUser] = useMutation(DELETE_CURRENT_USER);
|
const [deleteCurrentUser] = useMutation(DELETE_CURRENT_USER);
|
||||||
const formatMessage = useFormatMessage();
|
const formatMessage = useFormatMessage();
|
||||||
const { data: currentUser } = useCurrentUser();
|
const { data } = useCurrentUser();
|
||||||
|
const currentUser = data?.data;
|
||||||
|
|
||||||
const authentication = useAuthentication();
|
const authentication = useAuthentication();
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
@@ -24,7 +25,7 @@ function DeleteAccountDialog(props) {
|
|||||||
authentication.updateToken('');
|
authentication.updateToken('');
|
||||||
await apolloClient.clearStore();
|
await apolloClient.clearStore();
|
||||||
navigate(URLS.LOGIN);
|
navigate(URLS.LOGIN);
|
||||||
}, [deleteCurrentUser, currentUser?.data]);
|
}, [deleteCurrentUser, currentUser]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<ConfirmationDialog
|
<ConfirmationDialog
|
||||||
|
@@ -7,7 +7,8 @@ import useCurrentUser from 'hooks/useCurrentUser';
|
|||||||
|
|
||||||
const Chatwoot = ({ ready }) => {
|
const Chatwoot = ({ ready }) => {
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
const { data: currentUser } = useCurrentUser();
|
const { data } = useCurrentUser();
|
||||||
|
const currentUser = data?.data;
|
||||||
const matchSmallScreens = useMediaQuery(theme.breakpoints.down('md'));
|
const matchSmallScreens = useMediaQuery(theme.breakpoints.down('md'));
|
||||||
|
|
||||||
React.useEffect(function initiateChatwoot() {
|
React.useEffect(function initiateChatwoot() {
|
||||||
@@ -24,17 +25,17 @@ const Chatwoot = ({ ready }) => {
|
|||||||
|
|
||||||
React.useEffect(
|
React.useEffect(
|
||||||
function initiateUser() {
|
function initiateUser() {
|
||||||
if (!currentUser?.data?.id || !ready) return;
|
if (!currentUser?.id || !ready) return;
|
||||||
window.$chatwoot.setUser(currentUser.data?.id, {
|
window.$chatwoot.setUser(currentUser.id, {
|
||||||
email: currentUser?.data?.email,
|
email: currentUser.email,
|
||||||
name: currentUser?.data?.fullName,
|
name: currentUser.fullName,
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!matchSmallScreens) {
|
if (!matchSmallScreens) {
|
||||||
window.$chatwoot.toggleBubbleVisibility('show');
|
window.$chatwoot.toggleBubbleVisibility('show');
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
[currentUser?.data, ready, matchSmallScreens],
|
[currentUser, ready, matchSmallScreens],
|
||||||
);
|
);
|
||||||
React.useLayoutEffect(
|
React.useLayoutEffect(
|
||||||
function hideChatwoot() {
|
function hideChatwoot() {
|
||||||
|
@@ -21,7 +21,8 @@ import usePaddle from 'hooks/usePaddle.ee';
|
|||||||
|
|
||||||
export default function UpgradeFreeTrial() {
|
export default function UpgradeFreeTrial() {
|
||||||
const { data: plans, isLoading: isPaymentPlansLoading } = usePaymentPlans();
|
const { data: plans, isLoading: isPaymentPlansLoading } = usePaymentPlans();
|
||||||
const { data: currentUser } = useCurrentUser();
|
const { data } = useCurrentUser();
|
||||||
|
const currentUser = data?.data;
|
||||||
const { loaded: paddleLoaded } = usePaddle();
|
const { loaded: paddleLoaded } = usePaddle();
|
||||||
const [selectedIndex, setSelectedIndex] = React.useState(0);
|
const [selectedIndex, setSelectedIndex] = React.useState(0);
|
||||||
const selectedPlan = plans?.data?.[selectedIndex];
|
const selectedPlan = plans?.data?.[selectedIndex];
|
||||||
@@ -30,13 +31,13 @@ export default function UpgradeFreeTrial() {
|
|||||||
const handleCheckout = React.useCallback(() => {
|
const handleCheckout = React.useCallback(() => {
|
||||||
window.Paddle.Checkout?.open({
|
window.Paddle.Checkout?.open({
|
||||||
product: selectedPlan.productId,
|
product: selectedPlan.productId,
|
||||||
email: currentUser?.data?.email,
|
email: currentUser?.email,
|
||||||
passthrough: JSON.stringify({
|
passthrough: JSON.stringify({
|
||||||
id: currentUser?.data?.id,
|
id: currentUser?.id,
|
||||||
email: currentUser?.data?.email,
|
email: currentUser?.email,
|
||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
}, [selectedPlan, currentUser?.data]);
|
}, [selectedPlan, currentUser]);
|
||||||
|
|
||||||
if (isPaymentPlansLoading || !plans?.data?.length) return null;
|
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] =
|
const [showDeleteAccountConfirmation, setShowDeleteAccountConfirmation] =
|
||||||
React.useState(false);
|
React.useState(false);
|
||||||
const enqueueSnackbar = useEnqueueSnackbar();
|
const enqueueSnackbar = useEnqueueSnackbar();
|
||||||
const { data: currentUser } = useCurrentUser();
|
const { data } = useCurrentUser();
|
||||||
|
const currentUser = data?.data;
|
||||||
const formatMessage = useFormatMessage();
|
const formatMessage = useFormatMessage();
|
||||||
const [updateCurrentUser] = useMutation(UPDATE_CURRENT_USER);
|
const [updateCurrentUser] = useMutation(UPDATE_CURRENT_USER);
|
||||||
|
|
||||||
@@ -62,7 +63,7 @@ function ProfileSettings() {
|
|||||||
optimisticResponse: {
|
optimisticResponse: {
|
||||||
updateCurrentUser: {
|
updateCurrentUser: {
|
||||||
__typename: 'User',
|
__typename: 'User',
|
||||||
id: currentUser?.data?.id,
|
id: currentUser?.id,
|
||||||
fullName,
|
fullName,
|
||||||
email,
|
email,
|
||||||
},
|
},
|
||||||
@@ -87,7 +88,7 @@ function ProfileSettings() {
|
|||||||
<Grid item xs={12} justifyContent="flex-end">
|
<Grid item xs={12} justifyContent="flex-end">
|
||||||
<StyledForm
|
<StyledForm
|
||||||
defaultValues={{
|
defaultValues={{
|
||||||
...currentUser?.data,
|
...currentUser,
|
||||||
password: '',
|
password: '',
|
||||||
confirmPassword: '',
|
confirmPassword: '',
|
||||||
}}
|
}}
|
||||||
|
Reference in New Issue
Block a user