diff --git a/api-js/src/locale/en/messages.js b/api-js/src/locale/en/messages.js index 100b2042f..3b6fd2bb8 100644 --- a/api-js/src/locale/en/messages.js +++ b/api-js/src/locale/en/messages.js @@ -365,6 +365,8 @@ 'Unable to update domain. Please try again.', 'Unable to update organization. Please try again.': 'Unable to update organization. Please try again.', + 'Unable to update password, authentication error occurred, please sign in again.': + 'Unable to update password, authentication error occurred, please sign in again.', 'Unable to update password, current password does not match. Please try again.': 'Unable to update password, current password does not match. Please try again.', 'Unable to update password, new passwords do not match. Please try again.': diff --git a/api-js/src/locale/en/messages.po b/api-js/src/locale/en/messages.po index df8e2dd3a..60a63e1d0 100644 --- a/api-js/src/locale/en/messages.po +++ b/api-js/src/locale/en/messages.po @@ -285,7 +285,7 @@ msgstr "Successfully dispatched one time scan." msgid "Successfully email verified account, and set TFA send method to email." msgstr "Successfully email verified account, and set TFA send method to email." -#: src/affiliation/mutations/invite-user-to-org.js:171 +#: src/affiliation/mutations/invite-user-to-org.js:172 msgid "Successfully invited user to organization, and sent notification email." msgstr "Successfully invited user to organization, and sent notification email." @@ -301,7 +301,7 @@ msgstr "Successfully removed organization: {0}." msgid "Successfully removed user from organization." msgstr "Successfully removed user from organization." -#: src/affiliation/mutations/invite-user-to-org.js:119 +#: src/affiliation/mutations/invite-user-to-org.js:120 msgid "Successfully sent invitation to service, and organization email." msgstr "Successfully sent invitation to service, and organization email." @@ -464,9 +464,9 @@ msgid "Unable to find verified organization. Please try again." msgstr "Unable to find verified organization. Please try again." #: src/affiliation/mutations/invite-user-to-org.js:79 -#: src/affiliation/mutations/invite-user-to-org.js:92 -#: src/affiliation/mutations/invite-user-to-org.js:147 -#: src/affiliation/mutations/invite-user-to-org.js:162 +#: src/affiliation/mutations/invite-user-to-org.js:93 +#: src/affiliation/mutations/invite-user-to-org.js:148 +#: src/affiliation/mutations/invite-user-to-org.js:163 msgid "Unable to invite user. Please try again." msgstr "Unable to invite user. Please try again." diff --git a/api-js/src/locale/fr/messages.js b/api-js/src/locale/fr/messages.js index 0b0ec120f..8642c2f49 100644 --- a/api-js/src/locale/fr/messages.js +++ b/api-js/src/locale/fr/messages.js @@ -180,6 +180,8 @@ 'Unable to two factor authenticate. Please try again.': 'todo', 'Unable to update domain. Please try again.': 'todo', 'Unable to update organization. Please try again.': 'todo', + 'Unable to update password, authentication error occurred, please sign in again.': + 'todo', 'Unable to update password, current password does not match. Please try again.': 'todo', 'Unable to update password, new passwords do not match. Please try again.': diff --git a/api-js/src/locale/fr/messages.po b/api-js/src/locale/fr/messages.po index 322c082fd..be769f704 100644 --- a/api-js/src/locale/fr/messages.po +++ b/api-js/src/locale/fr/messages.po @@ -285,7 +285,7 @@ msgstr "todo" msgid "Successfully email verified account, and set TFA send method to email." msgstr "todo" -#: src/affiliation/mutations/invite-user-to-org.js:171 +#: src/affiliation/mutations/invite-user-to-org.js:172 msgid "Successfully invited user to organization, and sent notification email." msgstr "todo" @@ -301,7 +301,7 @@ msgstr "todo" msgid "Successfully removed user from organization." msgstr "todo" -#: src/affiliation/mutations/invite-user-to-org.js:119 +#: src/affiliation/mutations/invite-user-to-org.js:120 msgid "Successfully sent invitation to service, and organization email." msgstr "todo" @@ -464,9 +464,9 @@ msgid "Unable to find verified organization. Please try again." msgstr "todo" #: src/affiliation/mutations/invite-user-to-org.js:79 -#: src/affiliation/mutations/invite-user-to-org.js:92 -#: src/affiliation/mutations/invite-user-to-org.js:147 -#: src/affiliation/mutations/invite-user-to-org.js:162 +#: src/affiliation/mutations/invite-user-to-org.js:93 +#: src/affiliation/mutations/invite-user-to-org.js:148 +#: src/affiliation/mutations/invite-user-to-org.js:163 msgid "Unable to invite user. Please try again." msgstr "todo" diff --git a/api-js/src/user/mutations/__tests__/update-user-password.test.js b/api-js/src/user/mutations/__tests__/update-user-password.test.js index 28c949bae..858b4674c 100644 --- a/api-js/src/user/mutations/__tests__/update-user-password.test.js +++ b/api-js/src/user/mutations/__tests__/update-user-password.test.js @@ -129,7 +129,15 @@ describe('authenticate user account', () => { updatedPasswordConfirm: "newtestpassword123" } ) { - status + result { + ... on UpdateUserPasswordResultType { + status + } + ... on UpdateUserPasswordError { + code + description + } + } } } `, @@ -155,7 +163,9 @@ describe('authenticate user account', () => { const expectedResponse = { data: { updateUserPassword: { - status: 'Password was successfully updated.', + result: { + status: 'Password was successfully updated.', + }, }, }, } @@ -235,7 +245,15 @@ describe('authenticate user account', () => { updatedPasswordConfirm: "newtestpassword123" } ) { - status + result { + ... on UpdateUserPasswordResultType { + status + } + ... on UpdateUserPasswordError { + code + description + } + } } } `, @@ -258,11 +276,19 @@ describe('authenticate user account', () => { }, ) - const error = [ - new GraphQLError('Authentication error, please sign in again.'), - ] + const error = { + data: { + updateUserPassword: { + result: { + code: 400, + description: + 'Unable to update password, authentication error occurred, please sign in again.', + }, + }, + }, + } - expect(response.errors).toEqual(error) + expect(response).toEqual(error) expect(consoleOutput).toEqual([ 'User attempted to update password, but the user id is undefined.', ]) @@ -281,7 +307,15 @@ describe('authenticate user account', () => { updatedPasswordConfirm: "newtestpassword123" } ) { - status + result { + ... on UpdateUserPasswordResultType { + status + } + ... on UpdateUserPasswordError { + code + description + } + } } } `, @@ -304,11 +338,19 @@ describe('authenticate user account', () => { }, ) - const error = [ - new GraphQLError('Unable to update password. Please try again.'), - ] + const error = { + data: { + updateUserPassword: { + result: { + code: 400, + description: + 'Unable to update password, authentication error occurred, please sign in again.', + }, + }, + }, + } - expect(response.errors).toEqual(error) + expect(response).toEqual(error) expect(consoleOutput).toEqual([ `User: 1 attempted to update their password, but no account is associated with that id.`, ]) @@ -327,7 +369,15 @@ describe('authenticate user account', () => { updatedPasswordConfirm: "newtestpassword123" } ) { - status + result { + ... on UpdateUserPasswordResultType { + status + } + ... on UpdateUserPasswordError { + code + description + } + } } } `, @@ -350,13 +400,19 @@ describe('authenticate user account', () => { }, ) - const error = [ - new GraphQLError( - 'Unable to update password, current password does not match. Please try again.', - ), - ] + const error = { + data: { + updateUserPassword: { + result: { + code: 400, + description: + 'Unable to update password, current password does not match. Please try again.', + }, + }, + }, + } - expect(response.errors).toEqual(error) + expect(response).toEqual(error) expect(consoleOutput).toEqual([ `User: ${user._key} attempted to update their password, however they did not enter the current password correctly.`, ]) @@ -375,7 +431,15 @@ describe('authenticate user account', () => { updatedPasswordConfirm: "oldtestpassword123" } ) { - status + result { + ... on UpdateUserPasswordResultType { + status + } + ... on UpdateUserPasswordError { + code + description + } + } } } `, @@ -398,13 +462,19 @@ describe('authenticate user account', () => { }, ) - const error = [ - new GraphQLError( - 'Unable to update password, new passwords do not match. Please try again.', - ), - ] + const error = { + data: { + updateUserPassword: { + result: { + code: 400, + description: + 'Unable to update password, new passwords do not match. Please try again.', + }, + }, + }, + } - expect(response.errors).toEqual(error) + expect(response).toEqual(error) expect(consoleOutput).toEqual([ `User: ${user._key} attempted to update their password, however the new passwords do not match.`, ]) @@ -423,7 +493,15 @@ describe('authenticate user account', () => { updatedPasswordConfirm: "password" } ) { - status + result { + ... on UpdateUserPasswordResultType { + status + } + ... on UpdateUserPasswordError { + code + description + } + } } } `, @@ -446,13 +524,19 @@ describe('authenticate user account', () => { }, ) - const error = [ - new GraphQLError( - 'Unable to update password, passwords are required to be 12 characters or longer. Please try again.', - ), - ] + const error = { + data: { + updateUserPassword: { + result: { + code: 400, + description: + 'Unable to update password, passwords are required to be 12 characters or longer. Please try again.', + }, + }, + }, + } - expect(response.errors).toEqual(error) + expect(response).toEqual(error) expect(consoleOutput).toEqual([ `User: ${user._key} attempted to update their password, however the new password does not meet GoC requirements.`, ]) @@ -478,7 +562,15 @@ describe('authenticate user account', () => { updatedPasswordConfirm: "newtestpassword123" } ) { - status + result { + ... on UpdateUserPasswordResultType { + status + } + ... on UpdateUserPasswordError { + code + description + } + } } } `, @@ -541,7 +633,15 @@ describe('authenticate user account', () => { updatedPasswordConfirm: "newtestpassword123" } ) { - status + result { + ... on UpdateUserPasswordResultType { + status + } + ... on UpdateUserPasswordError { + code + description + } + } } } `, @@ -567,7 +667,9 @@ describe('authenticate user account', () => { const expectedResponse = { data: { updateUserPassword: { - status: 'todo', + result: { + status: 'todo', + }, }, }, } @@ -647,7 +749,15 @@ describe('authenticate user account', () => { updatedPasswordConfirm: "newtestpassword123" } ) { - status + result { + ... on UpdateUserPasswordResultType { + status + } + ... on UpdateUserPasswordError { + code + description + } + } } } `, @@ -670,9 +780,18 @@ describe('authenticate user account', () => { }, ) - const error = [new GraphQLError('todo')] + const error = { + data: { + updateUserPassword: { + result: { + code: 400, + description: 'todo', + }, + }, + }, + } - expect(response.errors).toEqual(error) + expect(response).toEqual(error) expect(consoleOutput).toEqual([ 'User attempted to update password, but the user id is undefined.', ]) @@ -691,7 +810,15 @@ describe('authenticate user account', () => { updatedPasswordConfirm: "newtestpassword123" } ) { - status + result { + ... on UpdateUserPasswordResultType { + status + } + ... on UpdateUserPasswordError { + code + description + } + } } } `, @@ -714,9 +841,18 @@ describe('authenticate user account', () => { }, ) - const error = [new GraphQLError('todo')] + const error = { + data: { + updateUserPassword: { + result: { + code: 400, + description: 'todo', + }, + }, + }, + } - expect(response.errors).toEqual(error) + expect(response).toEqual(error) expect(consoleOutput).toEqual([ `User: 1 attempted to update their password, but no account is associated with that id.`, ]) @@ -735,7 +871,15 @@ describe('authenticate user account', () => { updatedPasswordConfirm: "newtestpassword123" } ) { - status + result { + ... on UpdateUserPasswordResultType { + status + } + ... on UpdateUserPasswordError { + code + description + } + } } } `, @@ -758,9 +902,18 @@ describe('authenticate user account', () => { }, ) - const error = [new GraphQLError('todo')] + const error = { + data: { + updateUserPassword: { + result: { + code: 400, + description: 'todo', + }, + }, + }, + } - expect(response.errors).toEqual(error) + expect(response).toEqual(error) expect(consoleOutput).toEqual([ `User: ${user._key} attempted to update their password, however they did not enter the current password correctly.`, ]) @@ -779,7 +932,15 @@ describe('authenticate user account', () => { updatedPasswordConfirm: "oldtestpassword123" } ) { - status + result { + ... on UpdateUserPasswordResultType { + status + } + ... on UpdateUserPasswordError { + code + description + } + } } } `, @@ -802,9 +963,18 @@ describe('authenticate user account', () => { }, ) - const error = [new GraphQLError('todo')] + const error = { + data: { + updateUserPassword: { + result: { + code: 400, + description: 'todo', + }, + }, + }, + } - expect(response.errors).toEqual(error) + expect(response).toEqual(error) expect(consoleOutput).toEqual([ `User: ${user._key} attempted to update their password, however the new passwords do not match.`, ]) @@ -823,7 +993,15 @@ describe('authenticate user account', () => { updatedPasswordConfirm: "password" } ) { - status + result { + ... on UpdateUserPasswordResultType { + status + } + ... on UpdateUserPasswordError { + code + description + } + } } } `, @@ -846,9 +1024,18 @@ describe('authenticate user account', () => { }, ) - const error = [new GraphQLError('todo')] + const error = { + data: { + updateUserPassword: { + result: { + code: 400, + description: 'todo', + }, + }, + }, + } - expect(response.errors).toEqual(error) + expect(response).toEqual(error) expect(consoleOutput).toEqual([ `User: ${user._key} attempted to update their password, however the new password does not meet GoC requirements.`, ]) @@ -874,7 +1061,15 @@ describe('authenticate user account', () => { updatedPasswordConfirm: "newtestpassword123" } ) { - status + result { + ... on UpdateUserPasswordResultType { + status + } + ... on UpdateUserPasswordError { + code + description + } + } } } `, diff --git a/api-js/src/user/mutations/update-user-password.js b/api-js/src/user/mutations/update-user-password.js index 3d0fd1afc..44f5f13d6 100644 --- a/api-js/src/user/mutations/update-user-password.js +++ b/api-js/src/user/mutations/update-user-password.js @@ -2,6 +2,8 @@ import { GraphQLString, GraphQLNonNull } from 'graphql' import { mutationWithClientMutationId } from 'graphql-relay' import { t } from '@lingui/macro' +import { updateUserPasswordUnion } from '../unions' + export const updateUserPassword = new mutationWithClientMutationId({ name: 'UpdateUserPassword', description: @@ -22,12 +24,11 @@ export const updateUserPassword = new mutationWithClientMutationId({ }, }), outputFields: () => ({ - status: { - type: GraphQLString, - description: 'The status if the user profile update was successful.', - resolve: async (payload) => { - return payload.status - }, + result: { + type: updateUserPasswordUnion, + description: + '`UpdateUserPasswordUnion` returning either a `UpdateUserPasswordResultType`, or `UpdateUserPasswordError` object.', + resolve: (payload) => payload, }, }), mutateAndGetPayload: async ( @@ -51,7 +52,13 @@ export const updateUserPassword = new mutationWithClientMutationId({ console.warn( `User attempted to update password, but the user id is undefined.`, ) - throw new Error(i18n._(t`Authentication error, please sign in again.`)) + return { + _type: 'error', + code: 400, + description: i18n._( + t`Unable to update password, authentication error occurred, please sign in again.`, + ), + } } // Get user from db @@ -61,7 +68,13 @@ export const updateUserPassword = new mutationWithClientMutationId({ console.warn( `User: ${userKey} attempted to update their password, but no account is associated with that id.`, ) - throw new Error(i18n._(t`Unable to update password. Please try again.`)) + return { + _type: 'error', + code: 400, + description: i18n._( + t`Unable to update password, authentication error occurred, please sign in again.`, + ), + } } // Check to see if current passwords match @@ -69,11 +82,13 @@ export const updateUserPassword = new mutationWithClientMutationId({ console.warn( `User: ${user._key} attempted to update their password, however they did not enter the current password correctly.`, ) - throw new Error( - i18n._( + return { + _type: 'error', + code: 400, + description: i18n._( t`Unable to update password, current password does not match. Please try again.`, ), - ) + } } // Check to see if new passwords match @@ -81,11 +96,13 @@ export const updateUserPassword = new mutationWithClientMutationId({ console.warn( `User: ${user._key} attempted to update their password, however the new passwords do not match.`, ) - throw new Error( - i18n._( + return { + _type: 'error', + code: 400, + description: i18n._( t`Unable to update password, new passwords do not match. Please try again.`, ), - ) + } } // Check to see if they meet GoC requirements @@ -93,11 +110,13 @@ export const updateUserPassword = new mutationWithClientMutationId({ console.warn( `User: ${user._key} attempted to update their password, however the new password does not meet GoC requirements.`, ) - throw new Error( - i18n._( + return { + _type: 'error', + code: 400, + description: i18n._( t`Unable to update password, passwords are required to be 12 characters or longer. Please try again.`, ), - ) + } } // Update password in DB @@ -117,6 +136,7 @@ export const updateUserPassword = new mutationWithClientMutationId({ console.info(`User: ${user._key} successfully updated their password.`) return { + _type: 'regular', status: i18n._(t`Password was successfully updated.`), } }, diff --git a/api-js/src/user/objects/__tests__/update-user-password-error.test.js b/api-js/src/user/objects/__tests__/update-user-password-error.test.js new file mode 100644 index 000000000..2f2937ed2 --- /dev/null +++ b/api-js/src/user/objects/__tests__/update-user-password-error.test.js @@ -0,0 +1,39 @@ +import { GraphQLInt, GraphQLString } from 'graphql' + +import { updateUserPasswordErrorType } from '../update-user-password-error' + +describe('given the updateUserPasswordErrorType object', () => { + describe('testing the field definitions', () => { + it('has an code field', () => { + const demoType = updateUserPasswordErrorType.getFields() + + expect(demoType).toHaveProperty('code') + expect(demoType.code.type).toMatchObject(GraphQLInt) + }) + it('has a description field', () => { + const demoType = updateUserPasswordErrorType.getFields() + + expect(demoType).toHaveProperty('description') + expect(demoType.description.type).toMatchObject(GraphQLString) + }) + }) + + describe('testing the field resolvers', () => { + describe('testing the code resolver', () => { + it('returns the resolved field', () => { + const demoType = updateUserPasswordErrorType.getFields() + + expect(demoType.code.resolve({ code: 400 })).toEqual(400) + }) + }) + describe('testing the description field', () => { + it('returns the resolved value', () => { + const demoType = updateUserPasswordErrorType.getFields() + + expect( + demoType.description.resolve({ description: 'description' }), + ).toEqual('description') + }) + }) + }) +}) diff --git a/api-js/src/user/objects/__tests__/update-user-password-result.test.js b/api-js/src/user/objects/__tests__/update-user-password-result.test.js new file mode 100644 index 000000000..b4688b7e5 --- /dev/null +++ b/api-js/src/user/objects/__tests__/update-user-password-result.test.js @@ -0,0 +1,24 @@ +import { GraphQLString } from 'graphql' + +import { updateUserPasswordResultType } from '../update-user-password-result' + +describe('given the updateUserPasswordResultType object', () => { + describe('testing the field definitions', () => { + it('has an status field', () => { + const demoType = updateUserPasswordResultType.getFields() + + expect(demoType).toHaveProperty('status') + expect(demoType.status.type).toMatchObject(GraphQLString) + }) + }) + + describe('testing the field resolvers', () => { + describe('testing the status resolver', () => { + it('returns the resolved field', () => { + const demoType = updateUserPasswordResultType.getFields() + + expect(demoType.status.resolve({ status: 'status' })).toEqual('status') + }) + }) + }) +}) diff --git a/api-js/src/user/objects/index.js b/api-js/src/user/objects/index.js index b3b39d2f4..123f126fe 100644 --- a/api-js/src/user/objects/index.js +++ b/api-js/src/user/objects/index.js @@ -7,5 +7,7 @@ export * from './send-phone-code-result' export * from './sign-in-error' export * from './sign-up-error' export * from './tfa-sign-in-result' +export * from './update-user-password-error' +export * from './update-user-password-result' export * from './user-personal' export * from './user-shared' diff --git a/api-js/src/user/objects/update-user-password-error.js b/api-js/src/user/objects/update-user-password-error.js new file mode 100644 index 000000000..7708ba610 --- /dev/null +++ b/api-js/src/user/objects/update-user-password-error.js @@ -0,0 +1,19 @@ +import { GraphQLInt, GraphQLObjectType, GraphQLString } from 'graphql' + +export const updateUserPasswordErrorType = new GraphQLObjectType({ + name: 'UpdateUserPasswordError', + description: + 'This object is used to inform the user if any errors occurred while updating their password.', + fields: () => ({ + code: { + type: GraphQLInt, + description: 'Error code to inform user what the issue is related to.', + resolve: ({ code }) => code, + }, + description: { + type: GraphQLString, + description: 'Description of the issue that was encountered.', + resolve: ({ description }) => description, + }, + }), +}) diff --git a/api-js/src/user/objects/update-user-password-result.js b/api-js/src/user/objects/update-user-password-result.js new file mode 100644 index 000000000..4ab81653f --- /dev/null +++ b/api-js/src/user/objects/update-user-password-result.js @@ -0,0 +1,15 @@ +import { GraphQLObjectType, GraphQLString } from 'graphql' + +export const updateUserPasswordResultType = new GraphQLObjectType({ + name: 'UpdateUserPasswordResultType', + description: + 'This object is used to inform the user that no errors were encountered while updating their password.', + fields: () => ({ + status: { + type: GraphQLString, + description: + 'Informs the user if their password was successfully updated.', + resolve: ({ status }) => status, + }, + }), +}) diff --git a/api-js/src/user/unions/__tests__/update-user-password-union.test.js b/api-js/src/user/unions/__tests__/update-user-password-union.test.js new file mode 100644 index 000000000..850aa2a90 --- /dev/null +++ b/api-js/src/user/unions/__tests__/update-user-password-union.test.js @@ -0,0 +1,48 @@ +import { + updateUserPasswordErrorType, + updateUserPasswordResultType, +} from '../../objects/index' +import { updateUserPasswordUnion } from '../update-user-password-union' + +describe('given the updateUserPasswordUnion', () => { + describe('testing the field types', () => { + it('contains updateUserPasswordResultType', () => { + const demoType = updateUserPasswordUnion.getTypes() + + expect(demoType).toContain(updateUserPasswordResultType) + }) + it('contains updateUserPasswordErrorType', () => { + const demoType = updateUserPasswordUnion.getTypes() + + expect(demoType).toContain(updateUserPasswordErrorType) + }) + }) + describe('testing the field selection', () => { + describe('testing the updateUserPasswordResultType', () => { + it('returns the correct type', () => { + const obj = { + _type: 'regular', + authResult: {}, + } + + expect(updateUserPasswordUnion.resolveType(obj)).toMatchObject( + updateUserPasswordResultType, + ) + }) + }) + describe('testing the updateUserPasswordErrorType', () => { + it('returns the correct type', () => { + const obj = { + _type: 'error', + error: 'sign-in-error', + code: 401, + description: 'text', + } + + expect(updateUserPasswordUnion.resolveType(obj)).toMatchObject( + updateUserPasswordErrorType, + ) + }) + }) + }) +}) diff --git a/api-js/src/user/unions/index.js b/api-js/src/user/unions/index.js index 38b33db64..0b1d33b56 100644 --- a/api-js/src/user/unions/index.js +++ b/api-js/src/user/unions/index.js @@ -3,3 +3,4 @@ export * from './reset-password-union' export * from './send-phone-code-union' export * from './sign-in-union' export * from './sign-up-union' +export * from './update-user-password-union' diff --git a/api-js/src/user/unions/update-user-password-union.js b/api-js/src/user/unions/update-user-password-union.js new file mode 100644 index 000000000..f5b63b38b --- /dev/null +++ b/api-js/src/user/unions/update-user-password-union.js @@ -0,0 +1,19 @@ +import { GraphQLUnionType } from 'graphql' +import { + updateUserPasswordErrorType, + updateUserPasswordResultType, +} from '../objects' + +export const updateUserPasswordUnion = new GraphQLUnionType({ + name: 'UpdateUserPasswordUnion', + description: + 'This union is used with the `updateUserPassword` mutation, allowing for users to update their password, and support any errors that may occur', + types: [updateUserPasswordErrorType, updateUserPasswordResultType], + resolveType({ _type }) { + if (_type === 'regular') { + return updateUserPasswordResultType + } else { + return updateUserPasswordErrorType + } + }, +}) diff --git a/frontend/schema.faker.graphql b/frontend/schema.faker.graphql index 80fa5f8aa..9fae6af14 100644 --- a/frontend/schema.faker.graphql +++ b/frontend/schema.faker.graphql @@ -1886,6 +1886,14 @@ type UpdateOrganizationPayload { clientMutationId: String } +# This object is used to inform the user if any errors occurred while updating their password. +type UpdateUserPasswordError { + # Error code to inform user what the issue is related to. + code: Int + # Description of the issue that was encountered. + description: String +} + input UpdateUserPasswordInput { # The users current password to verify it is the current user. currentPassword: String! @@ -1897,11 +1905,23 @@ input UpdateUserPasswordInput { } type UpdateUserPasswordPayload { - # The status if the user profile update was successful. - status: String + # `UpdateUserPasswordUnion` returning either a `UpdateUserPasswordResultType`, or `UpdateUserPasswordError` object. + result: UpdateUserPasswordUnion clientMutationId: String } +# This object is used to inform the user that no errors were encountered while updating their password. +type UpdateUserPasswordResultType { + # Informs the user if their password was successfully updated. + status: String +} + +# This union is used with the `updateUserPassword` mutation, allowing for users to +# update their password, and support any errors that may occur +union UpdateUserPasswordUnion = + UpdateUserPasswordError + | UpdateUserPasswordResultType + input UpdateUserProfileInput { # The updated display name the user wishes to change to. displayName: String diff --git a/frontend/src/EditableUserPassword.js b/frontend/src/EditableUserPassword.js index 0d1d3d9a0..6831b8df9 100644 --- a/frontend/src/EditableUserPassword.js +++ b/frontend/src/EditableUserPassword.js @@ -51,16 +51,42 @@ function EditableUserPassword() { position: 'top-left', }) }, - onCompleted() { - toast({ - title: t`Changed User Password`, - description: t`You have successfully updated your password.`, - status: 'success', - duration: 9000, - isClosable: true, - position: 'top-left', - }) - onClose() + onCompleted({ updateUserPassword }) { + if ( + updateUserPassword.result.__typename === + 'UpdateUserPasswordResultType' + ) { + toast({ + title: t`Changed User Password`, + description: t`You have successfully updated your password.`, + status: 'success', + duration: 9000, + isClosable: true, + position: 'top-left', + }) + onClose() + } else if ( + updateUserPassword.result.__typename === 'UpdateUserPasswordError' + ) { + toast({ + title: t`Unable to update your password, please try again.`, + description: updateUserPassword.result.description, + status: 'error', + duration: 9000, + isClosable: true, + position: 'top-left', + }) + } else { + toast({ + title: t`Incorrect send method received.`, + description: t`Incorrect updateUserPassword.result typename.`, + status: 'error', + duration: 9000, + isClosable: true, + position: 'top-left', + }) + console.log('Incorrect updateUserPassword.result typename.') + } }, }, ) diff --git a/frontend/src/graphql/mutations.js b/frontend/src/graphql/mutations.js index d801ce26c..e0d269dcf 100644 --- a/frontend/src/graphql/mutations.js +++ b/frontend/src/graphql/mutations.js @@ -161,7 +161,15 @@ export const UPDATE_USER_PASSWORD = gql` updatedPasswordConfirm: $updatedPasswordConfirm } ) { - status + result { + ... on UpdateUserPasswordResultType { + status + } + ... on UpdateUserPasswordError { + code + description + } + } } } `