How to access mainWindow outside the main.js file

I am working on a project using electron and reactjs. I use the IPCRenderer and IPCMain to trigger database calls between the frontend and the backend.

In order not to make the main.js file too long, I moved the code for ipcMain.on calls to another(ipcMainHandlers.js) file in another directory and require the file in the main.js file.

The challenge I have is how to access the mainWindow from inside that file. I tried adding the mainWindow to globals.shared, but it comes back with undefined. I have tried using remote, but that returns undefined for remote.

const path = require('path');
const url = require('url');

const { app, BrowserWindow } = require('electron');

let mainWindow;

function createWindow() {
  mainWindow = new BrowserWindow({
    width: 800,
    height: 600,
    webPreferences: {
      nodeIntegration: true,
      enableRemoteModule: true,
      preload: __dirname + '/preload.js'
    },
  });

  const startUrl =
    process.env.ELECTRON_START_URL ||
    url.format({
      pathname: path.join(__dirname, './build/index.html'),
      protocol: 'file:',
      slashes: true,
    });

  mainWindow.loadURL(startUrl);
  mainWindow.webContents.openDevTools();
  mainWindow.on('closed', function () {
    mainWindow = null;
  });
}

app.on('ready', createWindow);
app.on('window-all-closed', function () {
  if (process.platform !== 'darwin') {
    app.quit();
  }
});
app.on('activate', function () {
  if (mainWindow === null) {
    createWindow();
  }
});

require('./src/server/helpers/ipcMainHandler.js');

This is the ipcMainHandler file

const AuthController = require('../controller/Auth.controller');
const { SIGNIN_REQUEST, SIGNIN_RESPONSE } = require('../../common/events.js');
const { ipcMain, remote } = require('electron');


console.log(remote);

const currentWindow = remote.getCurrentWindow();
console.log(currentWindow)

ipcMain.on(SIGNIN_REQUEST, (event, data) => {
  const user = AuthController.userSignin({ ...data });
  currentWindow.send(SIGNIN_RESPONSE, user);
});

Any help is greatly appreciated.

This has been solved. I resolved it by using the event object.

ipcMain.on(SIGNIN_REQUEST, async (event, data) => {
  const user = await AuthController.userSignin({ ...data });
  event.sender.send(SIGNIN_RESPONSE, user);
});