I am trying to access
csrftoken sent in response header through
Django Rest Framework API to
Angular 8 , but unable to do that.The csrf token is visible in developer tools in Chrome.please help me to resolve this issue as i am trying this from 1 week.
the above snippet shows the csrf token in Set-Cookie section.I want to access this value in angular code so that i can send it in request to call an api.
I have attached Django Api settings.py file.
Below is my angular code where i am trying to access the the headers from response.
Login code which is calling django api and in response getting various headers.
login(email: string, password: string) {
this.email = email;
.pipe(tap((user) => {
localStorage.setItem('currentUser', JSON.stringify(user));
console.log(user);
console.log("csrftoken:" + user.headers.get('csrftoken')); // tring to access csrf using headers
this.currentUserSubject.next(user);
this.data.setLoggedIn(true);
console.log("cookie data:"+this.Cookie.get('csrftoken')); //trying to access using cookie
return user;
}));
}
All other headers are accessible except Set-Cookie:csrftoken response header. can anybody please help me out here?Any help will be appreciated.