priya_singh
priya_singh

Reputation: 2488

Why is every API request creating a new session?

I am moving my project from AngularJS to Angular and it is creating a different session for each request; why? I have used withCredentials, this is user.service.ts:

loginUser(username,password) {
    var params = "emailId="+username + "&password="+ password;
    var headers = new Headers();
    headers.append('Content-Type', 'application/x-www-form-urlencoded');
    let options = new RequestOptions({ headers: headers, withCredentials: true });
    return this.authHttp.post(this.baseUrl+'authenticate/login?'+params, options)
    .map((response: Response) => response.json())
    .catch(this.handleError);
  }

getUserDetails() {
    var headers = new Headers();
    headers.append('Content-Type', 'application/x-www-form-urlencoded');
    let options = new RequestOptions({ headers: headers, withCredentials: true });
    return this.authHttp.get(this.baseUrl+'user/getUserDetails', options)
    .map((response: Response) => response.json())
    .catch(this.handleError);
  }

And this is my component:

this.userService.loginUser(email,password).subscribe(
        data => {
          if(data.hasOwnProperty('status')) {
            if(data.status != null && data.status != "") {
              if(data.status.toLowerCase() == 'active') {
                $(".login_btn + .sign-btn").css("display","block");
                $(".resend-error").html("");
                this.activationMsg = "";
                this.userService.getUserDetails().subscribe(
                data => {
                  console.log(data);
                },error => {

                });

              }
            }
          }
       });

Upvotes: 0

Views: 445

Answers (0)

Related Questions