I am looking at introducing the login system to the Electron [0] application, which I create, but get stuck in the processing of the session. Basically, I want to save the user session so that it remains between application restarts (if the "Remember me" option is enabled).
I need to use an existing back-end that works with cookie authentication, and I can't change anything there.
From the Electron documentation on the Session [1] object, I realized that I had to use a section, for example fe persist:someName , to have persistent storage, but this does not persist between application restarts, as it seems.
The way I'm setting a cookie right now is as follows:
// main-process/login.js const session = require('electron').session; const currentSession = session.fromPartition('persist:someName').cookies; currentSession.set({ name: 'myCookie', url: 'https://www.example.com', value: 'loggedin=1', expirationDate: 1531036000 }, function(error) { console.log('Cookie set'); if (error) { console.dir(error); } });
After that, I see the output of Cookie set , but when I restart the application and run the following code:
// main.js const session = require('electron').session; const currentSession = session.fromPartition('persist:someName').cookies; currentSession.get({}, function(error, cookies) { console.dir(cookies); if (error) { console.dir(error); } });
Returned result: [] .
Any guidance regarding what I am doing wrong or need to be done differently will be greatly appreciated!
[0] http://electron.atom.io
[1] http://electron.atom.io/docs/api/session/
Revell
source share