Repository: 4ian/GDevelop
File: newIDE/app/src/LoginProvider/LocalLoginProvider.js (JavaScript)

Code before:
    } catch (error) {
      console.error('Error while login:', error);
      throw error;
    }
  }

  async loginOrSignupWithProvider({
    provider,
    signal,
  }: {|
    provider: IdentityProvider,
    signal?: AbortSignal,
  |}) {
    if (signal && signal.aborted) {
      return Promise.reject(
        new UserCancellationError(
          'Login or Signup with provider already aborted.'
        )
      );
    }
    const promise = new Promise((resolve, reject) => {
      // Listen for abort event on signal
      if (signal) {
        signal.addEventListener('abort', () => {
          terminateWebSocket();
        });
      }
      setupAuthenticationWebSocket({
        onConnectionEstablished: connectionId => {
          if (signal && signal.aborted) return;
          const url = new URL(authenticationPortalUrl);
          url.searchParams.set('connection-id', connectionId);
          url.searchParams.set('provider', provider);
          url.searchParams.set('env', isDev ? 'dev' : 'live');
          Window.openExternalURL(url.toString());
        },
        onTokenReceived: async ({
          provider,
          data,
        }: {|
          provider: 'apple' | 'google' | 'github',
          data: any,
        |}) => {
          if (signal && signal.aborted) return;
          try {
            const credential =
              provider === 'google'
                ? GoogleAuthProvider.credential(data.credential)
                : provider === 'github'
                ? GithubAuthProvider.credential(data.accessToken)
                : new OAuthProvider('apple.com').credential({

Review comment (refactor):
this seemed duplicated in this file and the browser one.
This was always causing an error in the console because the signal always aborts (we trigger it when we close the dialog)
I don't think this deserves to raise an error as it's the expected path?

Code after:
    } catch (error) {
      console.error('Error while login:', error);
      throw error;
    }
  }

  async loginOrSignupWithProvider({
    provider,
    signal,
  }: {|
    provider: IdentityProvider,
    signal?: AbortSignal,
  |}) {
    if (signal && signal.aborted) {
      return Promise.reject(
        new UserCancellationError(
          'Login or Signup with provider already aborted.'
        )
      );
    }
    const promise = new Promise((resolve, reject) => {
      // Listen for abort event on signal
      if (signal) {
        signal.addEventListener('abort', () => {
          terminateWebSocket();
          reject(
            new UserCancellationError(
              'Login or Signup with provider already aborted.'
            )
          );
        });
      }
      setupAuthenticationWebSocket({
        onConnectionEstablished: connectionId => {
          if (signal && signal.aborted) return;
          const url = new URL(authenticationPortalUrl);
          url.searchParams.set('connection-id', connectionId);
          url.searchParams.set('provider', provider);
          url.searchParams.set('env', isDev ? 'dev' : 'live');
          Window.openExternalURL(url.toString());
        },
        onTokenReceived: async ({
          provider,
          data,
        }: {|
          provider: 'apple' | 'google' | 'github',
          data: any,
        |}) => {
          if (signal && signal.aborted) return;
          try {
            const credential =