Skip to content

The open alternative to Salesforce, designed for AI.

Fix error when token invalid (#20972)

martmullfbae66de8af6
diff --git a/packages/twenty-server/src/engine/core-modules/jwt/services/jwt-wrapper.service.ts b/packages/twenty-server/src/engine/core-modules/jwt/services/jwt-wrapper.service.ts
index d4b271c0d95..c3218efc082 100644
--- a/packages/twenty-server/src/engine/core-modules/jwt/services/jwt-wrapper.service.ts
+++ b/packages/twenty-server/src/engine/core-modules/jwt/services/jwt-wrapper.service.ts
@@ -137,7 +137,10 @@ export class JwtWrapperService {
const payload = this.decode<JwtPayload>(token, { json: true });
if (!isDefined(payload)) {
- throw new AuthException('No payload', AuthExceptionCode.UNAUTHENTICATED);
+ throw new AuthException(
+ 'Token invalid.',
+ AuthExceptionCode.UNAUTHENTICATED,
+ );
}
const { key, algorithm } = await this.resolveVerificationKey(token);
diff --git a/packages/twenty-server/test/integration/rest/suites/rest-api-core-authentication.integration-spec.ts b/packages/twenty-server/test/integration/rest/suites/rest-api-core-authentication.integration-spec.ts
index ce4c8d3a59a..926d4d8f467 100644
--- a/packages/twenty-server/test/integration/rest/suites/rest-api-core-authentication.integration-spec.ts
+++ b/packages/twenty-server/test/integration/rest/suites/rest-api-core-authentication.integration-spec.ts
@@ -27,7 +27,7 @@ describe('Core REST API Authentication', () => {
});
});
- it('should return an Unauthenticated when no token is provided', async () => {
+ it('should return an Unauthenticated when a malformed token is provided', async () => {
await makeRestAPIRequest({
method: 'post',
path: `/people`,
@@ -36,7 +36,7 @@ describe('Core REST API Authentication', () => {
.expect(401)
.expect((res) => {
expect(res.body.error).toBe('UNAUTHENTICATED');
- expect(res.body.messages[0]).toBe('No payload');
+ expect(res.body.messages[0]).toBe('Token invalid.');
});
});