简体   繁体   中英

Node js server side sessions for mobile applications

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, ie Store the user information in the session on login and use the same information for later api calls.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM