Non-Electron Session Cookies

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/

+7
javascript cookies session electron
source share
1 answer

An alternative would be to view electron-json-storage . Using this plugin, you can write JSON to the system file for the entire duration of the user’s work, and then remember this file when loading the application to replace the user "state".

0
source share

All Articles