I wish to create an application using node-webkit which does the simple job to open a remote web application. The web application has some cookie based authentication. Considering that the user has signed-in successfully, how can the required cookies be retained, so that the next time the application runs, the user will be authenticated?
Asked
Active
Viewed 3,042 times
9
-
Also stuck in the same problem! – Mitermayer Reis Dec 09 '15 at 04:22
2 Answers
9
You can get auth cookies using this instructions: https://github.com/nwjs/nw.js/wiki/window#windowcookies
Save it with prefered method: https://github.com/nwjs/nw.js/wiki/Save-persistent-data-in-app
On next start just check that record exists, and set cookies with method from 1.
Should be something like this:
var gui = require('nw.gui');
var win = gui.Window.get();
function login() {
var opts = {};
if(localStorage.auth) {
opts.cookies: [
'Auth': localStorage.auth
];
}
someRequest.get(opts, function(result) {
if(result)
localStorage.auth = win.cookies.get('auth');
});
}

Nazar Sakharenko
- 1,007
- 6
- 11
1
As of 2018, NW.js retains cookies and other persistent browser data by default. These are stored in %LOCALAPPDATA%/name-in-manifest/
in Windows or equivalent depending on OS. Nothing is required from the application itself, you do not have to persist cookie data manually in local storage.

Mahn
- 16,261
- 16
- 62
- 78
-
I facing the same issue of session not storing with latest NWJS 0.52.0 release as well, I'm also providing the following parameter `--user-data-dir='/Users/sunil/sunil/temp/userdatadir/profile1'` in `chromium-args`. Any idea why it is not storing the session, or what can be the problem? Also, created a question. I'll be thankful if you can provide your guidance - https://stackoverflow.com/q/68427188/819866 – Sunil Kumar Jul 18 '21 at 09:24