Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Generate Server Side session using Angular 5 (REST Webservices)

I'm working on Angular-5 and Spring framework. In spring framework we are making webservices using RESTEG and in Angular. I'm calling webservices from Angular-5 services.

Now problem is angular is working on 4200. And Tomcat is working on 8080 port. So, server side session in spring is not generating when I'm calling it through webservices.

Webservices works fine I'm able to call webservices and get response from webservices. But I'm not able to generate session which is generated on Back-End.

I have tried with proxy server also of Angular-5 and proxy works fine. For Proxy setup I'm using this question and it works fine :- angular-cli server - how to proxy API requests to another server?

I'm able to get request and response from it but after creating proxy I have the same issue that session is not creating.

Note :- When I made a build from angular-5 (ng build) and Put it in Tomcat then session works fine but while developing the webservices. I'm not able to generate session.

Example :- I have a webservice, Url1 :- http://localhost:8080/MacromWeb/ws/login

And I'm calling webservices from angular js which is on port 4200.

Url2 :- http://localhost:4200/#/login with parameter email and password.

So, when I'm calling webservices from angular it works fine it gives me response as well but the session which is created on server side is not generating.

like image 564
Bhavin Avatar asked Mar 28 '26 02:03

Bhavin


1 Answers

There is no session being shared in this kind of architecture (this is not related to Angular itself). It happens with any kind of app that has the client-side apart of the server (the browser, where the javascript runs, has no access to the server's session. This is different scenario, when you are writing some kind of app that uses server-side rendering template, like PHP, Rails, Java with Velocity or other template engine, etc...). What usually is done is use web tokens to handle security between client and server side.

You can take a look at this full example, based on Angular.

like image 104
Christian Benseler Avatar answered Mar 31 '26 03:03

Christian Benseler



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!