STEFAN LARIE
STEFAN LARIE

Reputation: 35

Set-cookie present in response but not set in browser (Application/cookes) Angular

Hi I'm building a client using typescript 10+ after I log in I receive a set-cookie with JSESSIONID and since is an HttpOnly true I can`t auto set it in the browser and somehow I expect this to be automated

I need to set it to the browser on every response and gipe it back at every request from the Server

  logIn(restUserDTO: RestUserDTO): Observable<any> {
    const haderParameters = {
      'Content-Type': 'application/json',
      'Accept': 'application/json',
      'Access-Control-Allow-Headers': 'Content-Type',
      'Authorization' :'BASIC '+ btoa(restUserDTO.username+":"+restUserDTO.password)
    }
    const haderOprions = {                                                                                                                                                                                 
      headers:new HttpHeaders(haderParameters) 
    };
    return this.http.post(constants.serverUrl+'api/rest/wout/login',null,haderOprions)
  } 

this is my code for logging in what I`m missing?

thank you for your time

[1]: https://i.sstatic.net/qES19.png

Upvotes: 2

Views: 1783

Answers (1)

Andrei
Andrei

Reputation: 12151

if you want cookies to work both ways you have to include credentials for your requests

http.post('url', null, {...haderOprions, withCredentials: true});

Upvotes: 1

Related Questions