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

As per title, just adding logs to troubleshoot:
https://github.com/twentyhq/twenty/issues/13103
This commit is contained in:
Charles Bochet
2025-11-24 19:49:02 +01:00
committed by GitHub
parent 30b6907c44
commit b2472b30c4
3 changed files with 21 additions and 0 deletions
@@ -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);
@@ -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);
}
@@ -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;
}