please forgive me if my question seems to have and answer. These don't works for me.
Basically I new in angular 6. I use http post
to authenticate user. My code looks like this.
onSubmit(value){
const httpOptions = {
headers: new HttpHeaders({ 'Content-Type': 'application/json' }),
observe: 'response' as 'body'
};
this.http.post(Globals.authEndPoint, value, {observe: 'response'})
.subscribe(function(res){
console.log(res);
});
}
On the server side:
app.use(function(req, res, next) {
res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Headers", "*");
if (req.method === 'OPTIONS'){
res.header('Access-Control-Allow-Methods', 'PUT, POST, PATCH, DELETE, GET' );
return res.status(200).json({})
}
next();
});
and this:
res.status(200).header( 'X-Auth-Token', 'token-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x').send(user);
my request in angular is done like this:
I have found a question like my mine, but the answer is not working for my case.
I think I am doing something wrong. How can I get token directly in post response.
Any ideas ?
update:
I have tried the answer listed below.
getConfigResponse(value): Observable<HttpResponse<Config>> {
return this.http.post<Config>( Globals.authEndPoint, value, {observe: 'response'});
}