Shoaib Iqbal
Shoaib Iqbal

Reputation: 2730

Unable to read certain cookies

i am trying to read cookies from browser in order to setup an authguard. I am trying to check if cookies are setup then user is logged in otherwise not. For this purpose i am using ngx-cookie-service. Here is code for getting value from cookies.

import {UserAuthService} from '../services';
import { CookieService } from 'ngx-cookie-service';

@Injectable()
export class AuthService {

constructor(
  private cookieService: CookieService,
}

  getSessionid() {
    this.cookieService.set('test', '123');
    console.log(this.cookieService.get('test'));
    console.log(this.cookieService.get('sessionid'));
    console.log(this.cookieService.get('csrftoken'));
    console.log(this.cookieService.get('messages'));
    return this.cookieService.get('sessionid') || null;
  } 
}

In above code it is printing certain values correctly in console such as test and csrftoken but messages and sessionid is blank where as in application tab i can see all the cookies. Here is a screenshot my application tab. enter image description here

and here is screenshot my console enter image description here

Anybody having idea what's wrong here?

Upvotes: 7

Views: 1698

Answers (1)

Dibzmania
Dibzmania

Reputation: 2014

In case you never found the answer -

That's because the cookies that are not printing are 'httpOnly'. You would a tick against those cookies on the 7th column of your first screenshot.

https://owasp.org/www-community/HttpOnly

Upvotes: 3

Related Questions