I have a sailsjs backend for API's and I want to use Angular4 for my frontend. I was wondering, how can I handle sessions on Angular? I tried reading the documentation and was unable to come up with anything.
Specifically I need to be able to handle the login, log out, CSRF protection, etc. Is it possible to use Angular4 in Sails because Sails has all of that built in?
As you want to use sails with Angular4 you may need add sails.io.js in your index.html as <script src="/assets/sails.io/sails.io.js"></script> ,keeping your sails.io.js in assets/sails.io/ folder then import SailsModule and register the sails module in your in app.module.ts .Also add
imports:[SailsModule.forRoot()]
You may need to inject SailsService in the constructor and ngOnInit() call the connect() method of SailsService. Then you can use request(options):Observable method of SailsService to get the request(check http://sailsjs.com/documentation/reference/web-sockets/socket-client/io-socket-request and check http://sailsjs.com/documentation/concepts/sessions) with the help of req.session you can get session value and property.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With