I am trying to sending login details but response error is
showing csrf token is missing. How can i send a csrf token from angular 2
to backend Django.
import { Injectable } from '@angular/core';
import { HttpClient, HttpHeaders} from '@angular/common/http';
import { Observable } from 'rxjs/Observable';
import { Cookie } from 'ng2-cookies';
import 'rxjs/add/operator/map';
@Injectable()
export class AuthenticationService {
constructor(private http: HttpClient){}
login(username:string,password:string){
return this.http.post<any>('/api/auth',{username:username,password:password},)
.map(user => {
//login successful if there a jwt token in the response
if(user && user.token){
localStorage.setItem('currentUser',JSON.stringify(user));
}
return user;
})
}
logout(){
//remove user from local storage to log user out
localStorage.removeItem('CurrentUser');
}
}