Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

393
Vistas
how to pass Auth Token from login window to app window in electron

I created an app in electron with react. I made two windows: login window and app window. In the login window, I set up a basic HTML form and I call the login endpoint from being like this:

async function login() {
  const response = await loginResponse(
    usernameInput.value,
    passwordInput.value
  );
  if (response?.invalidData === true) {
    alert("Wrong credentials!");
    return;
  }
  return ipcRenderer.send("open-app", response?.token, response?.displayName);
}

The event open-app it's for creating an app window and sending a token, displayName to react app:

ipcMain.on("open-app", async (e, token, displayName) => {
    console.log(token, displayName);
    if (appWindow) {
      appWindow.focus();
      return;
    }
    appWindow = new BrowserWindow({
      width: 1200,
      height: 900,
      webPreferences: {
        nodeIntegration: true,
        contextIsolation: false,
        enableRemoteModule: true,
      },
    });

    appWindow.webContents.on("dom-ready", (e) => {
      appWindow.webContents.send("auth-data", {
        token,
        displayName,
      });
    });

    appWindow.loadURL(
      isDev
        ? "http://localhost:3000"
        : `file://${__dirname}/../build/index.html`
    );
});

And in my App.js I save token in local storage:

useEffect(() => {
    ipcRenderer.on("auth-data", async (data) => {
      console.log(data);
      const { token, displayName } = data;
      console.log(token);
      if (token && displayName) {
        window.localStorage.setItem("auth", token);
        window.localStorage.setItem("displayName", displayName);
        await apiService.markOnline(token);
      }
    });
  }, []);

the problem it's the token doesn't save or if it's saved it doesn't update in localstorage when I re-open the app. How to send and update properly the token between the windows?

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda