Skip to content

The open alternative to Salesforce, designed for AI.

Add logs to debug user being disconnected randomly (#16037)

Charles Bochetb2472b30c4d4
diff --git a/packages/twenty-front/src/modules/apollo/hooks/useApolloFactory.ts b/packages/twenty-front/src/modules/apollo/hooks/useApolloFactory.ts
index ef1e9fca12d..99cf502ac81 100644
--- a/packages/twenty-front/src/modules/apollo/hooks/useApolloFactory.ts
+++ b/packages/twenty-front/src/modules/apollo/hooks/useApolloFactory.ts
@@ -64,6 +64,8 @@ export const useApolloFactory = (options: Partial<Options<any>> = {}) => {
setTokenPair(tokenPair);
},
onUnauthenticatedError: () => {
+ // eslint-disable-next-line no-console
+ console.log('onUnauthenticatedError, resetting state');
setTokenPair(null);
setCurrentUser(null);
setCurrentWorkspaceMember(null);
diff --git a/packages/twenty-front/src/modules/apollo/services/apollo.factory.ts b/packages/twenty-front/src/modules/apollo/services/apollo.factory.ts
index fe242b29029..268d3800c41 100644
--- a/packages/twenty-front/src/modules/apollo/services/apollo.factory.ts
+++ b/packages/twenty-front/src/modules/apollo/services/apollo.factory.ts
@@ -131,6 +131,8 @@ export class ApolloFactory<TCacheShape> implements ApolloManager<TCacheShape> {
attempts: {
max: 2,
retryIf: (error) => {
+ // eslint-disable-next-line no-console
+ console.log('retryIf error from retryLink', error);
if (this.isAuthenticationError(error)) {
return false;
}
@@ -147,11 +149,17 @@ export class ApolloFactory<TCacheShape> implements ApolloManager<TCacheShape> {
renewToken(uri, getTokenPair())
.then((tokens) => {
if (isDefined(tokens)) {
+ // eslint-disable-next-line no-console
+ console.log('setTokenPair from handleTokenRenewal');
onTokenPairChange?.(tokens);
cookieStorage.setItem('tokenPair', JSON.stringify(tokens));
}
})
.catch(() => {
+ // eslint-disable-next-line no-console
+ console.log(
+ 'Failed to renew token, triggering unauthenticated error from handleTokenRenewal',
+ );
onUnauthenticatedError?.();
}),
).flatMap(() => forward(operation));
@@ -221,6 +229,8 @@ export class ApolloFactory<TCacheShape> implements ApolloManager<TCacheShape> {
onErrorCb?.(graphQLErrors);
for (const graphQLError of graphQLErrors) {
if (graphQLError.message === 'Unauthorized') {
+ // eslint-disable-next-line no-console
+ console.log('Unauthorized, triggering token renewal');
return handleTokenRenewal(operation, forward);
}
@@ -233,6 +243,8 @@ export class ApolloFactory<TCacheShape> implements ApolloManager<TCacheShape> {
return;
}
case 'UNAUTHENTICATED': {
+ // eslint-disable-next-line no-console
+ console.log('UNAUTHENTICATED, triggering token renewal');
return handleTokenRenewal(operation, forward);
}
case 'FORBIDDEN': {
@@ -259,6 +271,10 @@ export class ApolloFactory<TCacheShape> implements ApolloManager<TCacheShape> {
this.isRestOperation(operation) &&
this.isAuthenticationError(networkError as ServerError)
) {
+ // eslint-disable-next-line no-console
+ console.log(
+ 'Authentication error, triggering token renewal from errorLink',
+ );
return handleTokenRenewal(operation, forward);
}
diff --git a/packages/twenty-front/src/modules/apollo/utils/getTokenPair.ts b/packages/twenty-front/src/modules/apollo/utils/getTokenPair.ts
index 85381369ccc..564caa49916 100644
--- a/packages/twenty-front/src/modules/apollo/utils/getTokenPair.ts
+++ b/packages/twenty-front/src/modules/apollo/utils/getTokenPair.ts
@@ -7,6 +7,9 @@ export const getTokenPair = (): AuthTokenPair | undefined => {
const stringTokenPair = cookieStorage.getItem('tokenPair');
if (!isDefined(stringTokenPair)) {
+ // eslint-disable-next-line no-console
+ console.log('tokenPair is undefined');
+
return undefined;
}