I have a simple electron app that wraps around a web app that prompts for username and password.
Problems:
1) When the user inputs the wrong credentials and the authWindow appears again. With the right credentials the second time login does not happen.
2) When the user inputs the wrong credentials twice, the authWindow no longer appears.
Any help is appreciated.
Here is my code:
const { app, BrowserWindow, ipcMain } = require('electron');
app.on("login", (event, webContents, request, authInfo, callback) => {
event.preventDefault();
createAuthWindow().then(credentials => {
callback(credentials.username, credentials.password);
});
});
function createAuthWindow() {
authWindow = new BrowserWindow({
show: false,
width: 400,
height: 200,
webPreferences: {
nodeIntegration: true
},
title: "Authentication",
});
authWindow.on('ready-to-show', function (){
authWindow.show();
});
authWindow.loadFile('password-form.html');
return new Promise((resolve, reject) => {
ipcMain.once('password-form-submission', (event, username, password) => {
authWindow.close();
const credentials = {
username,
password
};
resolve(credentials);
});
});
}
function createChatWindow() {
chatWindow = new BrowserWindow({
show: false,
width: 1000,
height: 800,
webPreferences: {
devTools: true
},
icon: __dirname + '/build/icon.png',
title: "Messenger",
});
chatWindow.once('ready-to-show', function (){
chatWindow.show();
});
chatWindow.loadURL('https://example.com');
chatWindow.webContents.openDevTools();
}
app.on('ready', createChatWindow);