diff --git a/api-gateway/src/api/service/account.ts b/api-gateway/src/api/service/account.ts index 9dcf34a7f5..8ea2adf2d5 100644 --- a/api-gateway/src/api/service/account.ts +++ b/api-gateway/src/api/service/account.ts @@ -129,7 +129,7 @@ export class AccountApi { } catch (error) { new Logger().error(error, ['API_GATEWAY']); if (error.message.includes('already exists')) { - throw new HttpException('An account with the same name already exists.', HttpStatus.CONFLICT); + throw new HttpException(error.message, HttpStatus.CONFLICT); } throw new HttpException(error.message, HttpStatus.INTERNAL_SERVER_ERROR); } diff --git a/auth-service/src/api/account-service.ts b/auth-service/src/api/account-service.ts index 5152232042..399e2b8848 100644 --- a/auth-service/src/api/account-service.ts +++ b/auth-service/src/api/account-service.ts @@ -25,6 +25,7 @@ import { IUser, UserRole } from '@guardian/interfaces'; +import { USER_REQUIRED_PROPS } from '../constants/index.js'; const { sign, verify } = pkg; @@ -60,8 +61,16 @@ export class AccountService extends NatsService { if (Date.now() > decryptedToken.expireAt) { throw new Error('Token expired'); } + const user = await new DataBaseHelper(User).findOne({ username: decryptedToken.username }); - return new MessageResponse(user); + + const userRequiredProps = {} + + for(const prop of Object.values(USER_REQUIRED_PROPS)) { + userRequiredProps[prop] = user[prop]; + } + + return new MessageResponse(userRequiredProps); } catch (error) { return new MessageError(error); } diff --git a/auth-service/src/constants/index.ts b/auth-service/src/constants/index.ts new file mode 100644 index 0000000000..cf5eca6aca --- /dev/null +++ b/auth-service/src/constants/index.ts @@ -0,0 +1 @@ +export { REQUIRED_PROPS as USER_REQUIRED_PROPS } from './user.js'; diff --git a/auth-service/src/constants/user.ts b/auth-service/src/constants/user.ts new file mode 100644 index 0000000000..6a31717136 --- /dev/null +++ b/auth-service/src/constants/user.ts @@ -0,0 +1,10 @@ +export const REQUIRED_PROPS = { + STATUS_CODE: 'status_code', + REASON: 'reason', + USER_NAME: 'username', + DID: 'did', + PARENT: 'parent', + HEDERA_ACCOUNT_ID: 'hederaAccountId', + ROLE: 'role', + ID: 'id', +}; diff --git a/e2e-tests/cypress/e2e/api-tests/accounts/getSession.cy.js b/e2e-tests/cypress/e2e/api-tests/accounts/getSession.cy.js index 7bf81dfcf3..036941b1a9 100644 --- a/e2e-tests/cypress/e2e/api-tests/accounts/getSession.cy.js +++ b/e2e-tests/cypress/e2e/api-tests/accounts/getSession.cy.js @@ -16,9 +16,7 @@ context('Accounts', { tags: '@accounts' }, () => { expect(response.status).to.eq(STATUS_CODE.OK) expect(response.body).to.have.property('id') expect(response.body).to.have.property('username', 'StandardRegistry') - expect(response.body).to.have.property('password') expect(response.body).to.have.property('did') - expect(response.body).to.have.property('walletToken') expect(response.body).to.have.property('hederaAccountId') expect(response.body).to.have.property('role') }) @@ -50,7 +48,6 @@ context('Accounts', { tags: '@accounts' }, () => { }).then((response) => { expect(response.status).to.eq(200) expect(response.body).to.have.property('id') - expect(response.body).to.have.property('password') expect(response.body.role).eq('USER') }) }) diff --git a/e2e-tests/cypress/e2e/api-tests/accounts/postRegister.cy.js b/e2e-tests/cypress/e2e/api-tests/accounts/postRegister.cy.js index 12e188af76..db34233d32 100644 --- a/e2e-tests/cypress/e2e/api-tests/accounts/postRegister.cy.js +++ b/e2e-tests/cypress/e2e/api-tests/accounts/postRegister.cy.js @@ -182,7 +182,7 @@ context("Accounts", { tags: "@accounts" }, () => { }, failOnStatusCode:false, }).then(response => { - expect(response.status).eql(STATUS_CODE.ERROR); + expect(response.status).eql(STATUS_CODE.CONFLICT); expect(response.body.message).eql("An account with the same name already exists."); }); }); diff --git a/e2e-tests/cypress/support/api/api-const.js b/e2e-tests/cypress/support/api/api-const.js index 6dae67ee76..c42027068b 100644 --- a/e2e-tests/cypress/support/api/api-const.js +++ b/e2e-tests/cypress/support/api/api-const.js @@ -15,6 +15,7 @@ export const STATUS_CODE = { UNAUTHORIZED: 401, FORBIDDEN: 403, NOT_FOUND: 404, + CONFLICT: 409, UNPROCESSABLE: 422, ERROR: 500, };