0

Is there any way to keep server side sessions in node js for requests coming through mobile applictions, Or it is in a way compulsory to use other methods like jwt?

As we do in Web applications, i.e Store the user information in the session on login and use the same information for later api calls.

Parth Acharya
  • 545
  • 3
  • 13
  • sessions are cookies and in request headers, so keep the header, sessions are kept. jwt can work with cookie/session or without, it signs and verify. if you need user state in mobile, in webview only you can use localstorage to keep a token, or use cookie/session or bridge to appdata or file – Josh Lin Feb 01 '18 at 07:31
  • never destory the webview you use for login and reuse it, then session should keep – Josh Lin Feb 01 '18 at 07:37

1 Answers1

1

Yes, there is and the simplest solutions is to use JWT, you can implement jwt authentication in you node.js server with any approach you want like: passport-jwt, express-jwt,... or even yourself with just jsonwebtoken npm package.

then for keeping mobile application authenticated with server, store the jwt token in mobile local storage and when app is opened just check the storage for if the token is exist or not and when there is jut add the token to the header and practically your mobile app keep a seesion open with server.

and for more information about jwt i ask a question about difference between session and cookie that might help you: Authentication: JWT usage vs session

Pourya8366
  • 3,424
  • 4
  • 21
  • 28