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.
and here is screenshot my console
Anybody having idea what's wrong here?
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
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